企业微信截图_a4158715-4dec-46b6-8778-f2c36bdf14d1.png
@objc func yeBtnClick()
{ // 点击 Btn 触发方法:
yeUIAlertCtrlActionSheet()
}
func yeUIAlertCtrlActionSheet()
{
//--- 1. 初始化控件 及其 显示的信息:
let alert = UIAlertController(title: "Information", message: "What's your favorite?", preferredStyle: UIAlertController.Style.actionSheet) // .Style.actionSheet 的样式;
//--- 2. 添加 弹窗上的Btn: (可添加多个Btn)
// style: .default: Btn的文字是蓝色显示; style: .destructive: Btn的文字是红色显示;
// style: .cancel: 的Btn 只能有一个;(.default和.destructive 都可以有多个)
let eBtn1 = UIAlertAction(title: "Btn1-Fishing", style: .default, handler: {(alerts: UIAlertAction) -> Void in
print("I like fishing")
})
alert.addAction(eBtn1)
let eBtn2 = UIAlertAction(title: "Btn2-Hunting", style: .default, handler: {(alerts: UIAlertAction) -> Void in
print("I like hunting")
})
alert.addAction(eBtn2)
// 2.3 style: .destructive: Btn的文字是红色显示;
let eBtn3 = UIAlertAction(title: "Btn3-Nothing", style: .destructive, handler: {(alerts: UIAlertAction) -> Void in
print("Btn3 -A Life of Nonsense.")
})
alert.addAction(eBtn3)
// 2.4: cancel Btn:
let eBtnCancel = UIAlertAction(title: "Btn4-Nothing", style: .cancel, handler: {(alerts: UIAlertAction) -> Void in
print("BtnCancel- A Life of Nonsense.")
})
alert.addAction(eBtnCancel)
//--- 3. 弹窗 UIAlertCtrl 消息窗口;
self.present(alert, animated: true, completion: nil) //(模态的形式)弹窗 UIAlertCtrl 消息窗口;
}