美文网首页
iOS 对话框使用(UIAlertController)

iOS 对话框使用(UIAlertController)

作者: 小小土豆dev | 来源:发表于2018-12-19 17:22 被阅读0次

普通警告对话框

普通警告对话框

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)

相关文章

网友评论

      本文标题:iOS 对话框使用(UIAlertController)

      本文链接:https://www.haomeiwen.com/subject/wwojkqtx.html