要实现这种:
swift popup dialog
cocoa touch – How would I create a UIAlertView in Swift? – Stack Overflow
swift UIAlertAction example
ios – How do I code an UIAlertAction in Swift? – Stack Overflow
代码:
let quitAlertController = UIAlertController(title: "确认", message: "确认要退出吗?", preferredStyle: UIAlertControllerStyle.Alert) let cancelAlertAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil) quitAlertController.addAction(cancelAlertAction) let sureAlertAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: doQuitHandler) quitAlertController.addAction(sureAlertAction) self.presentViewController(quitAlertController, animated: true, completion: nil) func doQuitHandler(alerAction:UIAlertAction){ print("doQuitHandler: alerAction=\(alerAction)") //doQuitHandler: alerAction=<UIAlertAction: 0x7f8c23a5d4a0 Title = "确定" Descriptive = "(null)" Image = 0x0> } |
效果:
把“确定”从
UIAlertActionStyle.Default
换成
UIAlertActionStyle.Destructive
let sureAlertAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Destructive, handler: doQuitHandler) |
效果是红色字体:
转载请注明:在路上 » [已解决]swift实现选择对话框