标签:
双选
//实例化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)
标签:
原文地址:http://www.cnblogs.com/SadlyCodes/p/4231586.html