企業(yè)微信截圖_a4158715-4dec-46b6-8778-f2c36bdf14d1.png
@objc func yeBtnClick()
{ // 點擊 Btn 觸發(fā)方法:
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的文字是藍(lán)色顯示; 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) //(模態(tài)的形式)彈窗 UIAlertCtrl 消息窗口;
}