从ios8之后,系统的弹框    UIAlertView 与  UIActionSheet 两个并在一了起, 使用了一个新的控制器叫 UIAlertController

UIAlertController的基本使用

创建UIAlertController

Title:显示的标题
message:标题底部显示的描述信息
preferredStyle:弹框的样式
样式分为两种:
UIAlertControllerStyleActionSheet:
UIAlertControllerStyleAlert 两种样式分别显示如下: 第一步:创建控制器
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确定要退出嘛?" message:@“显示的信息" preferredStyle:UIAlertControllerStyleActionSheet]; 第二步:创建按钮
弹框当中的每一个按钮分别对应一个 UIAlertAction UIAlertAction创建方式如下:
actionWithTitle:按钮要显示的文字
style:按钮要显示的样式
样式分为三种:
UIAlertActionStyleDefault:默认样式,默认按钮颜色为蓝色
UIAlertActionStyleCancel:设置按钮为取消.点击取消是,会动退出弹框.
注意:取消样式只能设置一个,如果有多个取消样式,则会发生错误.
UIAlertActionStyleDestructive:危险操作按钮,按钮颜色显示为红公
handler:点击按钮时调用Block内部代码. UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消");
}]; UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消");
[self.navigationController popViewControllerAnimated:YES];
}]; 第三步:添加按钮
把创建的UIAlertAction添加到控制器当中.
[alertController addAction:action];
[alertController addAction:action1]; 除了添加按钮之外,还可以添加文本框,
添加文本框的前提是UIAlertController的样式必须得要是UIAlertControllerStyleAlert样式.否则会直接报错
添加文本框方法为:
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @“文本框点位文字";
}]; 运行效果为: 通过控制器的textFields属性获取添加的文本框.注意textFields它是一个数组.
UITextField *textF = alertController.textFields.lastObject; 第四步:显示弹框.(相当于show操作)
[self presentViewController:alertController animated:YES completion:nil];

UIAlertController基本使用的更多相关文章

  1. UIAlertController

    楼主在整理项目的警告,于是乎你懂的. 然后自己整理了一下以后方便自己忘了之后能及时找到它 关于UIAlertController .h文件的解析 /** 关于UIAlertController的解析 ...

  2. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  3. UIAlertController使用

    // 将UIAlertController模态出来 相当于UIAlertView show 的方法// 初始化一个一个UIAlertController    // 参数preferredStyle: ...

  4. IOS UIAlertController 使用方法

    在很多种语言中,alert都表示弹窗操作,弹窗功能非常有用,不仅可以用于正式的app功能中,也可以在调试中使用.在OC中,UIAlertController类用来控制弹窗操作.在IOS 8.0之前, ...

  5. UI控件(UIAlertController)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *_button = [UIBut ...

  6. UIAlertController 部分用法及属性

    //创建UIAlertController:初始化UIAlertController 需要使用alertControllerWithTitle UIAlertController *alertCont ...

  7. iOS--UIAlertView与UIAlertController和UIAlertAction之间的事儿

      iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备 ...

  8. 开始使用 UIAlertController 吧

    UIAlertView 与 UIActionSheet UIAlertView 样式 实现 - (void)showAlertView { self.alertView = [[UIAlertView ...

  9. UI第十四节——UIAlertController

    - (void)viewDidLoad {    [super viewDidLoad];        UIButton *alertBtn = [UIButton buttonWithType:U ...

  10. iOS 8.0后使用UIAlertController

    iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...

随机推荐

  1. 【VLFeat】使用matlab版本计算HOG

    下载 vlfeat-0.9.18    http://www.vlfeat.org cd D:\program\vlfeat-0.9.18\toolbox

  2. Red5 1.0.5安装过程记录

    Red5从旧的服务器切换到了github上后,截至20150702仍未更新文档.为了搭建Red5开发环境,我像无头苍蝇一样乱转了很多博客和StackOverflow.藉此记录这次安装过程,希望能够帮助 ...

  3. 【原】Spark Rpc通信源码分析

    Spark 1.6+推出了以RPCEnv.RPCEndpoint.RPCEndpointRef为核心的新型架构下的RPC通信方式.其具体实现有Akka和Netty两种方式,Akka是基于Scala的A ...

  4. (3)I2C总线的字节格式,时钟同步和仲裁

    字节格式 发送到SDA线上的每个字节必须是8位.每次传输的字节数量是不受限制的.每个字节后必须跟着一个ACK应答位.数据从最高有效位(MSB)开始传输.如果从机要执行一些功能后才能接收或者发送新的完整 ...

  5. POJ2250 - Compromise(LCS+打印路径)

    题目大意 给定两段文本,问公共单词有多少个 题解 裸LCS... 代码: #include<iostream> #include<string> using namespace ...

  6. [置顶] 使用U盘安装ubuntu系统

    使用U盘安装ubuntu系统 在网上找了很多教程,都不起效,提示:“从光盘上读取数据出错”. 总结出了几个关键点. 首先,版本,Ubuntu 12.04 Server,一般的U盘安装都会报:“从光盘上 ...

  7. [struts2]struts结合ECharts的用法

    <script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script> < ...

  8. smarty对网页性能的影响--开启opcache

    在上一篇<smarty对网页性能的影响>中,默认没有开启opcache,于是我安装了一下zend opcache扩展,重新实验了一下,结果如下: 有smarty 用apache的ab命令进 ...

  9. HDU P4578 Transformation

    Problem Description Yuanfang is puzzled with the question below: There are n integers, a1, a2, …, an ...

  10. JavaScript- 获得TreeView CheckBox里选中项的值

    获得TreeView CheckBox里选中项的值,对JSDOM控制还不是很熟,感觉不太容易.试了很多次终于成功了. 代码如下 <body> <form id="form1 ...