1.前言  

在前段时间手机QQ:升级iOS8.3后,发图就崩的情况,
就是因为iOS8更新UIAlertController后,仍然使用UIAlertview导致的
具体原因分析 这个可以看腾讯团队发出来的总结分享。
 
在Xcode头文件中苹果也明确给出用UIAlertController替代UIAlertview和UIActionSheet的标识
 
 
 
所以iOS8以后我们还是使用苹果推荐的UIAlertController吧(这货居然是一个ViewController。。)
 

2.如何使用UIAlertController  

2.2.第一种创建方式——默认提示框  

最原始的init一般不用这种,默认是上拉菜单样式

import UIKit

class 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.cnblogs.com/qingche/
本文版权归作者和博客园共有,欢迎转载,但必须保留此段声明,且在文章页面明显位置给出原文连接。

最新文章

  1. js 为label标签和div标签赋值
  2. 重温WCF之数单向通讯、双向通讯、回调操作(五)
  3. Linux环境变量设置指南
  4. (01)odoo8.0_Ubuntu14.04源码安装
  5. footer居底
  6. 【转载】应广大群众的要求,今天开始连载《超容易的Linux系统管理入门书》一书
  7. HDU 2809 God of War(DP + 状态压缩)
  8. java学习之break 和 continue
  9. Smarty include
  10. lufylegend练习(1)帧速率
  11. CentOS 7.0开放指定端口
  12. 课堂作业Complex类的实现
  13. edgedb 内部pg 数据存储的探索 (五) 运行进程列表信息
  14. python使用itchat发送微信消息提醒
  15. Python爬虫、自动化常用库&amp;帮助文档URL
  16. 因子分析factor analysis_spss运用_python建模(推荐AAA)
  17. BZOJ.5338.[TJOI2018]xor(可持久化Trie)
  18. PHP冒泡排序-手写
  19. quartz Cron表达式解读
  20. Docker基于已有的镜像制新的镜像-Docker for Web Developers(3)

热门文章

  1. 利用RTTI实现Delphi的多播事件代理研究
  2. redis未授权弱口令检测脚本(redis未授权访问漏洞,利用redis写webshell)
  3. python自学之第一章——列表(一)
  4. 浅析Vue.js 中的条件渲染指令
  5. go_json解析
  6. 关于makefile中自动产生依赖的理解
  7. 虚拟机ubuntu磁盘扩容
  8. 20155236 《Java程序设计》实验五(网络编程与安全)实验报告
  9. 20155333 2016-2017-2 《Java程序设计》第十周学习总结
  10. 20155333 2016-2017-2 《Java程序设计》第4周学习总结