IOS8 UIAlertController 弹框
本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/35551769
IOS8中,Apple将UIActionSheet和UIAlertView整合成一个接口UIAlertController。
原来的是一个view,展示在window视图之上。现在改成了controller,展示方式变成由当前的controller直接present出来。
下面看看具体的接口:
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"This is Title"
- message:@"This is message"
- preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:[UIAlertAction actionWithTitle:@"Action 1 (Default Style)"
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction *action) {
- NSLog(@"Action 1 Handler Called");
- }]];
- [alert addAction:[UIAlertAction actionWithTitle:@"Action 2 (Cancel Style)"
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction *action) {
- NSLog(@"Action 2 Handler Called");
- }]];
- [alert addAction:[UIAlertAction actionWithTitle:@"Action 3 (Destructive Style)"
- style:UIAlertActionStyleDestructive
- handler:^(UIAlertAction *action) {
- NSLog(@"Action 3 Handler Called");
- }]];
- [self presentViewController:alert animated:YES completion:nil];
- <span style="font-family:Arial, Helvetica, sans-serif;">生成UIAlertController的时候可以指定title、message,通过preferredStyle可以指定具体是Alert还是</span><span style="color: rgb(61, 29, 129); font-family: Menlo; font-size: 14px;">ActionSheet</span>
- typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
- UIAlertControllerStyleActionSheet = 0,
- UIAlertControllerStyleAlert
- } NS_ENUM_AVAILABLE_IOS(8_0);
通过addAction接口添加具体按钮,设置按钮title、style和使用block方式直接加入按钮响应接口。
style有以下几种:
- typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
- UIAlertActionStyleDefault = 0,
- UIAlertActionStyleCancel,
- UIAlertActionStyleDestructive
- } NS_ENUM_AVAILABLE_IOS(8_0);
与原来的UIActionSheet和UIAlertView比较:
1、视觉上没有改变,跟之前的样式保持一致;
2、改为controller方式后,控件的生命周期能够更好的控制;方便的弹出和收起
3、当前controller弹出UIAlertController后,再次present controller必须在UIAlertController的基础上present。present后,UIAlertController会被盖住。而之前的UIActionSheet和UIAlertView由于是add在window上面的,当在弹出他们的controller基础上再present controller的话,UIActionSheet和UIAlertView弹框仍然保留在最上方。
4、修改为controller方式后,接口更加简单,而且按钮响应方式更加明了简介,不需要在设置delegate和实现响应的回调等。
IOS8 UIAlertController 弹框的更多相关文章
- UIAlertController:弹框4步走
对于大多数的App来说,弹框这种交互方式基本上是必不可少的.在新的iOS系统中(具体版本我忘了),以前的UIAlertView被弃用,而换成了现在的UIAlertController. UIAlite ...
- iOS8 UIAlertController弹出框中添加视图(例如日期选择器等等)
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerMode ...
- IOS 弹框AlterView的使用(IOS8.0以前使用)UIAlertController(IOS9.0使用)
#pragma mark - 代理方法 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath ...
- ios-消息弹框之UIAlertView, UIActionSheet以及UIAlertController小结
首先storyboard中创建对应按钮并拖线,来演示不同的效果 首先点击了actionSheet按钮效果如图 实现弹框需要遵守设置代理,遵守协议. 效果就是从底部向上弹起来的框框. 通过对按钮的点击输 ...
- 参考bootstrap中的popover.js的css画消息弹框
前段时间小颖的大学同学给小颖发了一张截图,图片类似下面这张图: 小颖当时大概的给她说了下,其实小颖也不知道上面那个三角形怎么画嘻嘻,给她说了DOM结构,具体的css让她自己百度,今天小颖自己参考boo ...
- 安卓客户端a标签长按弹框提示解决办法
昨天工作时候发现一个bug,是关于a标签的,在安卓客户端中,如果是a标签的话,长按会出现一个弹框,如图所示 是因为安卓客户端的长按触发机制,以后进行wap端开发的时候,如果用到跳转页面尽量不要用a标签 ...
- Jquary入门(添加 修改 表单元素)+ JSON+弹框
字符串拼接 计算机语言 都是 对 数据的处理(获取/修改数据) 添加元素 除了 固定的方法添加 以外 都是 字符串拼接(拼接成固定格式即可执行). 1.表单添加元素 append() 方 ...
- ios UIWebView自定义Alert风格的弹框
之前开发过一个App,因为公司之前写好了网页版的内容和安卓版本的App,我进去后老板要求我ios直接用网页的内容,而不需要自己再搭建框架.我一听,偷笑了,这不就是一个UIWebView吗?简单! 但是 ...
- weui 弹框中的单选效果
<!--性别修改弹框--> <div class="weui_dialog_alert" id="doctorSexDialog" style ...
随机推荐
- uva 10828 高斯消元求数学期望
Back to Kernighan-RitchieInput: Standard Input Output: Standard Output You must have heard the name ...
- 【CF1025A】Doggo Recoloring(签到)
题意:给定一个长度为 n 的小写字母串.可以将出现次数大于等于2的字母全部变成另一个小写字母,问最后能否将该小写字母串的所有字母变成同一个字母 n<=1e5 思路: #include<cs ...
- 【CF1027A】Palindromic Twist(模拟)
题意:输入T组字符串,每个字符串都必须改变一次,每个字母改变的规则是变成相邻的字母,字母a只能变b,z只能变y,判断改变后的字符依旧是否能够变成回文串 n<=1e2 思路: #include&l ...
- gulp前端自动化入门
一.从零开始搭建gulp前端自动化 1.首先安装nodejs 2.npm init 初始化 生成package.json 2.1 可以选装cnpm cnpm是淘宝提供的服务 安装:命令提示符执行npm ...
- 标准C程序设计七---65
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- hdu4183往返经过至多每个点一次/最大流
题意:从s到t,每个点有f值,只能从f值小的到大的,到T后回来,只能从f值大的到 小的,求可行否. 往返,其实就是俩条路过去(每个点最多一次),所以想到流量为2,跑最大流,看是否满2,又要每个点最多一 ...
- hdu 5690(模运算)
All X Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- LeetCode OJ——Remove Duplicates from Sorted List
http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ 链表的去重,要考虑链表的本质. #include <ios ...
- 计蒜客 微软大楼设计方案(RMQ)
题目链接 微软大楼设计方案 中文题就不说题意了~ 首先是简单版本 满足$1 <= n, m <= 50$ 那么设$c[i][j]$为从第$i$幢楼到第$j$幢楼的最低的那幢楼的高度 计算两 ...
- BZOJ——1622: [Usaco2008 Open]Word Power 名字的能量
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只 ...