UIAlertController 顯示警告訊息和選單

preferredStyle: .alert
preferredStyle: .actionSheet
style: .cancel 左邊為取消按鈕且粗體,style: .destructive 警示用的紅字
@IBAction func alertButtonClick(_ sender: UIButton) {switch sender {case singleAlertButton:let singleAlert = UIAlertController(title: "標題", message: "內容訊息", preferredStyle: .alert)singleAlert.addAction(UIAlertAction(title: "ok", style: .default, handler: nil))present(singleAlert, animated: true, completion: nil)case warningAlertButton:let warningAlert = UIAlertController(title: "刪除標題", message: "確定要刪除嗎?", preferredStyle: .alert)let deleteAction = UIAlertAction(title: "Delete", style: .destructive) { (UIAlertAction) inprint("按Delete後的動作")}warningAlert.addAction(deleteAction)let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler:  nil)warningAlert.addAction(cancelAction)present(warningAlert, animated: true, completion: nil)case enterAlertButton:let enterAlert = UIAlertController(title: "登入", message: "請輸入帳號密碼", preferredStyle: .alert)enterAlert.addTextField { (UITextField) inUITextField.placeholder = "帳號"}enterAlert.addTextField { (UITextField) inUITextField.placeholder = "密碼"// 如果要輸入密碼 這個屬性要設定為 trueUITextField.isSecureTextEntry = true}let okAction = UIAlertAction(title: "ok", style: .default, handler: nil)let cancelAction = UIAlertAction(title: "cancel", style: .cancel, handler: nil)enterAlert.addAction(okAction)enterAlert.addAction(cancelAction)present(enterAlert, animated: true, completion: nil)case menuAlertButton:let menuAlert = UIAlertController(title: "選單", message: "內容", preferredStyle: .actionSheet)let menuArray = ["紅茶","咖啡","牛奶"]for menu in menuArray {let menuAction = UIAlertAction(title: menu, style: .default, handler: nil)menuAlert.addAction(menuAction)}let cancelAction = UIAlertAction(title: "cancel", style: .cancel, handler: nil)menuAlert.addAction(cancelAction)present(menuAlert, animated: true, completion: nil)default:break}}

--

--