zoukankan      html  css  js  c++  java
  • 用swift写的两种形式的AlartView

    一、创建一个button

     var btnClik:UIButton  = UIButton(type: .Custom)

        override func viewDidLoad() {

            super.viewDidLoad()

            self.view.backgroundColor = UIColor.redColor()

            

            btnClik.frame = CGRectMake(0, 0, 60, 54)

            btnClik.backgroundColor = UIColor.blueColor()

            btnClik.center = CGPointMake(160, 200)

            btnClik.setTitle("戳我啊", forState:.Normal)

            btnClik.addTarget(self, action:"showAlertController", forControlEvents: .TouchUpInside)

            view.addSubview(btnClik)

        }

    button分别调用以下两个方法

    1.原始的alertView

    func showAlert(){

            let msgTitle:String = "欢迎光临"

            let message:String = "不要欢饮光临"

            let alert:UIAlertView = UIAlertView()

            alert.title = msgTitle;

            alert.message = message

            alert.addButtonWithTitle("现在去哪里")

            alert.show()

        }

     2.iOS系统9.0以后的alertView

        func showAlertController(){

            let title = "欢迎光临"

            let message = "不要欢迎光临"

            let btnLeft = "NO...."

            let btnRight = "现在带我走"

            

            let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)

            let actionLeft = UIAlertAction(title:btnLeft, style: .Cancel) { action in

                

                NSLog("Not so interested in the site.")

                

            }

            

            let actionRight = UIAlertAction(title:btnRight, style: .Default) { action in

                NSLog("Hook, line and sinker!")

        }

            alertController.addAction(actionLeft)

            alertController.addAction(actionRight)

            presentViewController(alertController, animated: true, completion: nil)

        }

        

  • 相关阅读:
    TP6框架中如何无刷新上传文件
    TP6框架设置验证码的宽度和高度后,验证码显示不全
    TP6模板缓存问题
    TP6管理后台实战第五天文章管理
    20211027技术人为什么建议写博客
    TP6管理后台实战第六天系统管理
    博客园自定义菜单
    xcat无法连接服务器
    lsf安装后配置
    xcat网络无盘启动——添加自定义安装包
  • 原文地址:https://www.cnblogs.com/baidaye/p/5099312.html
Copyright © 2011-2022 走看看