日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Swift - 警告提示框(UIAlertController)的用法

發布時間:2023/12/10 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Swift - 警告提示框(UIAlertController)的用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

import UIKitclass ViewController: UIViewController {override func viewDidLoad() {super.viewDidLoad()}override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {// 創建let alertController = UIAlertController(title: "提示", message: "你確定要離開?", preferredStyle:.Alert) // 設置2個UIAlertAction let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: nil) let okAction = UIAlertAction(title: "好的", style: .Default) { (UIAlertAction) in print("點擊了好的") } // 添加 alertController.addAction(cancelAction) alertController.addAction(okAction) // 彈出 self.presentViewController(alertController, animated: true, completion: nil) } }

// 除了彈出,還可以使用底部向上滑出的樣式// 注意:如果上拉菜單中有『取消』按鈕的話,那么它永遠都會出現在菜單的底部,不管添加的次序如何// 創建// preferredStyle 為 ActionSheetlet alertController = UIAlertController(title: "保存或刪除數據", message: "刪除數據將不可恢復", preferredStyle:.ActionSheet) // 設置2個UIAlertAction let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: nil) let deleteAction = UIAlertAction(title: "刪除", style: .Destructive, handler: nil) let saveAction = UIAlertAction(title: "保存", style: .Default, handler: nil) // 添加到UIAlertController alertController.addAction(cancelAction) alertController.addAction(saveAction) alertController.addAction(deleteAction) // 彈出 self.presentViewController(alertController, animated: true, completion: nil)

/*添加任意數量的文本輸入框(比如可以用來實現登錄框)*/let alertController = UIAlertController(title: "系統登錄", message: "請輸入用戶名和密碼", preferredStyle: UIAlertControllerStyle.Alert)alertController.addTextFieldWithConfigurationHandler { (textField:UITextField) in textField.placeholder = "用戶名" } alertController.addTextFieldWithConfigurationHandler { (textField:UITextField) in textField.placeholder = "密碼" textField.secureTextEntry = true } let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil) let okAction = UIAlertAction(title: "好的", style: UIAlertActionStyle.Default) { (UIAlertAction) in let login = alertController.textFields![0] let pwd = alertController.textFields![1] print("用戶名:\(login.text) 密碼:\(pwd.text)") } alertController.addAction(cancelAction) alertController.addAction(okAction) // 彈出 self.presentViewController(alertController, animated: true, completion: nil)

轉載于:https://www.cnblogs.com/Free-Thinker/p/6372952.html

總結

以上是生活随笔為你收集整理的Swift - 警告提示框(UIAlertController)的用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。