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)

        }

        

  • 相关阅读:
    第四章——不定积分必记公式
    高等数学思维导图——4.一元函数积分学【不定积分+定积分】
    算法很美(三)
    第三章——微分中值定理与导数必记公式
    详解洛必达法则
    高等数学思维导图——3.微分中值定理与导数的应用
    Python课程笔记(二)
    第二章——导数与微分必记公式
    高等数学思维导图——2.导数与微分
    第二章.给客户所需之物
  • 原文地址:https://www.cnblogs.com/baidaye/p/5099312.html
Copyright © 2011-2022 走看看