普通警告对话框
![](https://img.haomeiwen.com/i2559321/95c7ff106130aa82.png)
let alert = UIAlertController(title: "Information", message: "Are you a student?", preferredStyle: UIAlertController.Style.alert)
let yes = UIAlertAction.init(title: "Yes", style: UIAlertAction.Style.default) { (alerts) in
print("Yes.")
}
let no = UIAlertAction.init(title: "No", style: UIAlertAction.Style.default) { (alerts) in
print("No.")
}
alert.addAction(yes)
alert.addAction(no)
self.present(alert, animated: true, completion: nil)
动作表样式警告对话框
![](https://img.haomeiwen.com/i2559321/1588364ef0eb3d6a.png)
let alert = UIAlertController(title: "Information", message: "What's your favorite?", preferredStyle: UIAlertController.Style.actionSheet)
let fishing = UIAlertAction.init(title: "Fishing", style: UIAlertAction.Style.default) { (alerts) in
print("Fishing.")
}
let hunting = UIAlertAction.init(title: "Hunting", style: UIAlertAction.Style.destructive) { (alerts) in
print("Hunting.")
}
let nothing = UIAlertAction.init(title: "Nothing", style: UIAlertAction.Style.cancel) { (alerts) in
print("Nothing.")
}
alert.addAction(fishing)
alert.addAction(hunting)
alert.addAction(nothing)
self.present(alert, animated: true, completion: nil)
网友评论