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)

        }

        

  • 相关阅读:
    求最大公约数
    计算变量
    JavaScript高级浏览器原理V8引擎js执行原理
    JavaScript小游戏按下按钮移动方块
    黑马程序员WPF中的DoubleAnimation
    黑马程序员浅谈partial class的理解
    黑马程序员C#与Javascript变量、函数之间的相互调用
    黑马程序员关于工作流的模式
    黑马程序员C#解析HTML
    黑马程序员关于System.Collections空间
  • 原文地址:https://www.cnblogs.com/baidaye/p/5099312.html
Copyright © 2011-2022 走看看