国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOS-Swift:如何使用iOS8中的UIAlertController

2019-11-14 18:34:00
字體:
來源:轉載
供稿:網友

1.前言  

在前段時間手機QQ:升級iOS8.3后,發圖就崩的情況,
就是因為iOS8更新UIAlertController后,仍然使用UIAlertview導致的
具體原因分析 這個可以看騰訊團隊發出來的總結分享。
 
在Xcode頭文件中蘋果也明確給出用UIAlertController替代UIAlertview和UIActionSheet的標識
 
 
 
所以iOS8以后我們還是使用蘋果推薦的UIAlertController吧(這貨居然是一個ViewController。。)
 

2.如何使用UIAlertController  

2.2.第一種創建方式——默認提示框  

最原始的init一般不用這種,默認是上拉菜單樣式

import UIKitclass ViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }       override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {        // 單擊屏幕觸發                      //方式一        var alertVC = UIAlertController()        alertVC.title = "Title"        alertVC.message = "Hello,My name Saup"               //因為UIAlertController是控制器,所以我們現在得改用控制器彈出        self.PResentViewController(alertVC, animated: true, completion: nil)           }

 效果圖1:

 

2.2.第二種創建方式——自定義提示框  

UIAlertControllerStyle
UIAlertControllerStyle.Alert        對話框樣式
UIAlertControllerStyle.ActionSheet  上拉菜單樣式
注意第三個參數,要確定您選擇的是對話框樣式還是上拉菜單樣式。
 
 
UIAlertActionStyle
通過UIAlertActionStyle,可以選擇如下三種動作樣式:
常規(default)、取消(cancel)以及警示(destruective)。
UIAlertActionStyle.Default
UIAlertActionStyle.Cancel
UIAlertActionStyle.Destructive //“警告”樣式會默認把按鈕字體加紅
 
       override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {        // 單擊屏幕觸發               //方式二               //創建控制器        var alertVC = UIAlertController(title: "Title", message: "Please choose!", preferredStyle: UIAlertControllerStyle.ActionSheet)        //創建按鈕        var acSure = UIAlertAction(title: "Sure", style: UIAlertActionStyle.Default) { (UIAlertAction) -> Void in            print("click Sure")        }               var acCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in            print("click Cancel")        }//        var acDestuctive = UIAlertAction(title: "Destuctive", style: //UIAlertActionStyle.Destuctive) { (UIAlertAction) -> Void in//            print("click Destuctive")//        }               alertVC.addAction(acSure)        alertVC.addAction(acCancel)//      alertVC.addAction(acDestuctive)               //因為UIAlertController是控制器,所以我們現在得改用控制器彈出        self.presentViewController(alertVC, animated: true, completion: nil)            }

效果圖2:

 

2.3.第三種創建方式——文本對話框  

      override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {        // 單擊屏幕觸發               //方式三               //創建控制器        var alertVC = UIAlertController(title: "TextFiled", message: "Please input!", preferredStyle: UIAlertControllerStyle.Alert)        alertVC.addTextFieldWithConfigurationHandler { (tField:UITextField!) -> Void in                       tField.placeholder = "Account"        }                      alertVC.addTextFieldWithConfigurationHandler {(textField:UITextField!) -> Void in            textField.placeholder = "PassWord"            textField.secureTextEntry = true;        }               var acOK = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (alertAction:UIAlertAction!) -> Void in        }        var acCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (alertAction:UIAlertAction!) -> Void in        }               acOK.enabled = false               alertVC.addAction(acOK)        alertVC.addAction(acCancel)                             //因為UIAlertController是控制器,所以我們現在得改用控制器彈出        self.presentViewController(alertVC, animated: true, completion: nil)    }

效果圖3:

 

 

 

作者: 清澈Saup
出處: http://www.survivalescaperooms.com/qingche/
本文版權歸作者和博客園共有,歡迎轉載,但必須保留此段聲明,且在文章頁面明顯位置給出原文連接。

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遵义市| 华亭县| 同德县| 万山特区| 辉南县| 隆德县| 抚松县| 游戏| 澳门| 禄丰县| 沁水县| 内丘县| 铜川市| 赣榆县| 巴青县| 丁青县| 湛江市| 通河县| 富源县| 鄄城县| 上虞市| 景德镇市| 沅陵县| 永吉县| 息烽县| 尼木县| 石景山区| 历史| 新沂市| 六枝特区| 喀什市| 汾阳市| 丽水市| 姚安县| 正安县| 封开县| 彰武县| 壤塘县| 西乌珠穆沁旗| 保康县| 南投市|