UIAlertController基本使用
从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基本使用的更多相关文章
- UIAlertController
楼主在整理项目的警告,于是乎你懂的. 然后自己整理了一下以后方便自己忘了之后能及时找到它 关于UIAlertController .h文件的解析 /** 关于UIAlertController的解析 ...
- iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法
今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...
- UIAlertController使用
// 将UIAlertController模态出来 相当于UIAlertView show 的方法// 初始化一个一个UIAlertController // 参数preferredStyle: ...
- IOS UIAlertController 使用方法
在很多种语言中,alert都表示弹窗操作,弹窗功能非常有用,不仅可以用于正式的app功能中,也可以在调试中使用.在OC中,UIAlertController类用来控制弹窗操作.在IOS 8.0之前, ...
- UI控件(UIAlertController)
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *_button = [UIBut ...
- UIAlertController 部分用法及属性
//创建UIAlertController:初始化UIAlertController 需要使用alertControllerWithTitle UIAlertController *alertCont ...
- iOS--UIAlertView与UIAlertController和UIAlertAction之间的事儿
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备 ...
- 开始使用 UIAlertController 吧
UIAlertView 与 UIActionSheet UIAlertView 样式 实现 - (void)showAlertView { self.alertView = [[UIAlertView ...
- UI第十四节——UIAlertController
- (void)viewDidLoad { [super viewDidLoad]; UIButton *alertBtn = [UIButton buttonWithType:U ...
- iOS 8.0后使用UIAlertController
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...
随机推荐
- leecode single numer
http://www.acmerblog.com/leetcode-single-number-ii-5394.html acm之家的讲解总是那么到位 public class Solution { ...
- 搭建Windows Azure开发环境-环境搭建
虚拟机中运行 练习1:使用远程桌面连接到虚拟机 在本节中,你会登录到Windows Azure的门户网站,并使用Windows Azure库创建的Azure虚拟机. 任务1 -配置的Visual St ...
- HW3.13
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- Nyoj42 一笔画问题 (欧拉道路)
http://acm.nyist.net/JudgeOnline/problem.php?pid=42题目链接 #include <cstdio> #include <cstring ...
- OpenSSH 高级运用两则
00×0.相关介绍 OpenSSH(OpenBSD Secure Shell)使用 SSH 通过计算机网络加密通信的实现. 它是替换由 SSH Communications Security 所提供的 ...
- mongodb的查询操作符
本文地址:http://www.cnblogs.com/egger/archive/2013/05/04/3059374.html 欢迎转载 ,请保留此链接! 官方参考: http://docs. ...
- git 删除分支和删除文件夹
1.删除分支 1.1查看所有分支: git branch -a 得到结果: 1.2删除HEAD分支 git push origin --delete HEAD 2.删除文件夹 2.1 查看本地分支下的 ...
- 职责链模式vs状态模式区别
状态模式在具体状态里设置了下一状态. 而职责链模式是在客户端代码里设置了下一状态的处理对象. 如果状态模式里的任何一环缺失,将导致事情无法进行下去.职责链模式的链式在客户端连接的,也就是说,如果我们请 ...
- ListBox基础
关键点 在列表框生成后需要向其中加入或是删除行,可以利用: int AddString( LPCTSTR lpszItem )添加行, int DeleteString( UINT nIndex ...
- [React] React Fundamentals: transferPropsTo
the transferPropsTo method lets you easily push properties into your components to easily customize ...