iOS 对话框使用(UIAlertController)

2018-12-19  本文已影响0人  小小土豆dev

普通警告对话框

普通警告对话框

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)


动作表样式警告对话框

动作表样式警告对话框

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)

上一篇 下一篇

猜你喜欢

热点阅读