码迷,mamicode.com
首页 > 其他好文 > 详细

弹出对话框 UIAlertController

时间:2015-01-18 11:41:05      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

双选

//实例化UIAlertController
var av=UIAlertController(title: "??终极大考验??",message: "你爱妞妞妈?",preferredStyle: UIAlertControllerStyle.Alert)
//实例化第一个选项
        var act1 = UIAlertAction(title: "爱", style: UIAlertActionStyle.Default){
            (action: UIAlertAction!) -> Void in
            self.lbl1.text="you choosed 爱"  //回调设置lbl1的文本
        }
        //实例化第二个选项
        var act2 = UIAlertAction(title: "超爱", style: UIAlertActionStyle.Destructive){
            (action: UIAlertAction!) -> Void in
            self.lbl1.text="you choosed 超爱"
        }
        //将选项加入对话框
        av.addAction(act1)
        av.addAction(act2)
        
    //显示对话框
        self.presentViewController(av, animated: true, completion: nil)

文本框输入

        var alertController=UIAlertController(title: "请登录", message: "输入登录信息", preferredStyle: UIAlertControllerStyle.Alert)
        alertController.addTextFieldWithConfigurationHandler {
            (textField: UITextField!) -> Void in
            textField.placeholder = "登录"
        }
        alertController.addTextFieldWithConfigurationHandler {
            (textField: UITextField!) -> Void in
            textField.placeholder = "密码"
            textField.secureTextEntry = true
        }
        
        var okAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) {
            (action: UIAlertAction!) -> Void in
            var login = alertController.textFields?.first as UITextField
            var password = alertController.textFields?.last as UITextField
            self.lbl1.text=login.text+password.text
        }
        
        var cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Default,handler:nil)
        
        alertController.addAction(okAction)
        alertController.addAction(cancelAction)
        
        self.presentViewController(alertController, animated: true, completion: nil)

 

弹出对话框 UIAlertController

标签:

原文地址:http://www.cnblogs.com/SadlyCodes/p/4231586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!