1.前言
最原始的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:
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:
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.companysz.com/qingche/
本文版權歸作者和博客園共有,歡迎轉載,但必須保留此段聲明,且在文章頁面明顯位置給出原文連接。
|
新聞熱點
疑難解答