三种状态 常规(default)、取消(cancel)以及警示(destructive)
1,在中间有点击方法
let alertVC = UIAlertController(title: "提示", message: "我是提示框", preferredStyle: UIAlertControllerStyle.Alert)
let acSure = UIAlertAction(title: "确定", style: UIAlertActionStyle.Destructive) { (UIAlertAction) -> Void in
print("click Sure")
}
let acCancel = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in
print("click Cancel")
}
alertVC.addAction(acSure)
alertVC.addAction(acCancel)
self.presentViewController(alertVC, animated: true, completion: nil)
2,在中间无点击方法
let alertController = UIAlertController(title: "提示", message: "我是提示框",preferredStyle: .Alert)
let cancelAction1 = UIAlertAction(title: "确定", style: .Destructive, handler: nil)
let cancelAction2 = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
alertController.addAction(cancelAction1)
alertController.addAction(cancelAction2)
self.presentViewController(alertController, animated: true, completion: nil)
3,在底下有点击方法
let alertVC = UIAlertController(title: "提示", message: "我是提示框", preferredStyle: UIAlertControllerStyle.ActionSheet)
let acSure = UIAlertAction(title: "确定", style: UIAlertActionStyle.Destructive) { (UIAlertAction) -> Void in
print("click Sure")
}
let acCancel = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in
print("click Cancel")
}
alertVC.addAction(acSure)
alertVC.addAction(acCancel)
self.presentViewController(alertVC, animated: true, completion: nil)
4,在底下无点击方法
let alertController = UIAlertController(title: "提示", message: "我是提示框",preferredStyle: .ActionSheet)
let cancelAction1 = UIAlertAction(title: "确定", style: .Default, handler: nil)
let cancelAction2 = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
alertController.addAction(cancelAction1)
alertController.addAction(cancelAction2)
self.presentViewController(alertController, animated: true, completion: nil)
UIAlertView(title: "提示", message:"", delegate: nil, cancelButtonTitle: "确定").show()