• 用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)

        }

        

  • 相关阅读:
    ajax的调用
    jqurey的应用
    php数据访问数据层
    php租房子练习
    php投票
    Thinkphp 控制器
    ThinkPHP 框架基础
    php留言板
    php上传文件及头像预览
    php文件操作
  • 原文地址:https://www.cnblogs.com/baidaye/p/5099312.html
Copyright © 2020-2023  润新知