iOS8新特性(1)——UIAlertController
一、iOS8介绍
iOS8 新特性,主要是UI上进行了统一
//选项弹出等
-(void)alertViewOld
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;//4种方式
[alert show]; //如果要监听点击事件则需要去设置对应的代理,并在代理方法中操作
} //底部弹出
-(void)aletSheetOld
{
UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"犹豫" otherButtonTitles:@"确定", nil]; [action showInView:self.view];
}
2、而从iOS8开始, UIAlertController = UIAlertView + UIAlertSheet
#pragma mark -- new iOS8 -(void)new
{
//1、创建中间的弹出:UIAlertView
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"弹出信息" preferredStyle:UIAlertControllerStyleAlert]; //创建底部的弹出:UIAlertSheet
//UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"弹出信息" preferredStyle:UIAlertControllerStyleActionSheet]; //2、添加按钮(不需要代理了) //这里需要防止循环引用(可以通过新建一个自己的控制器继承UIAlertController,在dealloc中打印信息,验证是否有最终释放)
__weak typeof(alert) weakAlert = alert;
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"%@",[weakAlert.textFields.firstObject text]); }]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:nil]]; //3、添加文本框(只能是添加到UIAlertControllerStyleAlert的样式,如果是preferredStyle:UIAlertControllerStyleActionSheet的话会崩溃的)
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.textColor =[UIColor redColor];
textField.text = @""; //监听文字的改变(如果是用通知的话,移除的时机需要注意,点击确定或者取消的时候就需要去移除,比较麻烦)
[textField addTarget:self action:@selector(textFieldsValueDidChange:) forControlEvents:UIControlEventEditingChanged];
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.secureTextEntry = YES;
textField.text = @"";
}]; //4、弹出控制器,要想是不是用modal
[self presentViewController:alert animated:YES completion:nil];
} -(void)textFieldsValueDidChange:(UITextField *)textField
{
NSLog(@"%@",textField.text);
}
3、在iPhone和iPad中同时适用的方式
#pragma mark -- new iOS8 in iPad
/**
* 注意:
UIAlertControllerStyleActionSheet
1、不能有文本框
2、在iPad中,必须使用popover的形式展示 以后都是用present
*/
-(void)newInpad
{
//1、创建底部的弹出:UIAlertSheet
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"弹出信息" preferredStyle:UIAlertControllerStyleActionSheet]; // 1.1 这句代码可写可不写,因为默认就会以UIModalPresentationPopover的形式存在
alert.modalPresentationStyle = UIModalPresentationPopover; // 1.2 设置popover指向按钮(这句代码iPhone中会被忽略,iPad中才会实现)
alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem; //2、添加按钮(不需要代理了) //这里需要防止循环引用(可以通过新建一个自己的控制器继承UIAlertController,在dealloc中打印信息,验证是否有最终释放)
__weak typeof(alert) weakAlert = alert;
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"%@",[weakAlert.textFields.firstObject text]); }]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:nil]]; //4、弹出控制器,要想是不是用modal
[self presentViewController:alert animated:YES completion:nil];
}
注意:
UIAlertControllerStyleActionSheet
1、不能有文本框
2、在iPad中,必须使用popover的形式展示
iOS8新特性(1)——UIAlertController的更多相关文章
- iOS8 新特性
iOS8新特性主要体现在4方面 1.UIAlertController 对alert&actionSheet的封装 UIAlertController.h 提示框按钮的选择 typedef N ...
- ios8新特性widget开发-b
os8发布已经有一段时间了,伴随着ios8同时也出现了许多新的特性,ios系统将会越来越开放,这是好事.其中一个新特性就是在下拉通知栏里加入了个性的widget,开发者可以自己定义widget的样式内 ...
- iOS8新特性
1. App Extension Programming Guide 2.LocalAuthentication.framework - Touch ID Authentication 3.Local ...
- iOS8新特性(1)-UIPopoverPresentationController使用
从iOS 8开始,苹果提出新的 UIPopoverPresentationController代替UIPopoverController: 新的UIPopoverPresentationControl ...
- 利用iOS8新特性计算cell的实际高度
在计算cell的实际高度是 我们一般是通过计算frame 拿到最底部一个控件的最大Y值从而的到cell 的高度 算来算去 比较麻烦 其实,iOS8已经提供了直接通过Cell高度自适应的方法了,根 ...
- iOS iOS8新特性--UIPopoverPresentationController
1.回顾UIPopoverController的使用,下面这份代码只能在ipad下运行 // 初始化控制器,SecondViewController类继承自UIViewController Secon ...
- iOS8新特性之基于地理位置的消息通知UILocalNotification
苹果在WWDC2014上正式公布了全新的iOS8操作系统. 界面上iOS8与iOS7相比变化不大,只是在功能方面进行了完好. ...
- iOS8新特性之交互式通知
目前分为四个推送:用户推送,本地推送,远程推送,地理位置推送. if (IS_IOS8) { //1.创建消息上面要添加的动作(按钮的形式显示出来) UIMutableUserNotification ...
- Ios8新特性-应用程序扩展
一.什么是应用程序扩展? 应用程序扩展不是一个应用,它是主体应用程序(containing app)中一个单独的包,并能生成单独的二进制文件供其他应用调用. 个人感觉,类似于WP中的启动器,把系统当个 ...
随机推荐
- git push 后 链接总是灰色点击没有反应
情况描述: mymon是openfalcon的监控mysql插件,从GitHub拉下来后,改动源码后,提交到公司内部的gitlab上,发现提交上去的图标总是灰色的,点击进不去,如下图所示.怎么解决? ...
- ADCD 1.9 ZOS 配置 CTCI-W32 TCPIP 网络
试验步骤:两步走,第一步修改Hercules的配置文件 在hercules 配置文件末尾加上 0E20-0E21 CTCI -n 0A-00-27-00-00-00 192.168.5 ...
- PHP文本操作
1. 用PHP获取文件指定行或者随机行 <?php /*** * 功能: 随机获取一个文件里的某一行 * 实现: 先将文件读进一个数组: 随机获取0~数组长度-1之间的一个随机数:以这个随机数做 ...
- Android ScrollView 和ListView 一起使用的问题汇总
1.ScrollView 嵌套 ListView ,touch事件的截获问题. 参考 http://www.cnblogs.com/lqminn/archive/2013/03/02/2940194 ...
- CentOS “/lib64/libc.so.6: version `GLIBC_2.14′ not found”系统glibc版本太低
1.试图运行程序提示”libc.so.6: version `GLIBC_2.14′ not found”,原因是系统的glibc版本太低,软件编译时使用了较高版本的glibc引起的.2.查看系统gl ...
- Win7 在安装vs2010后向sql2008添加SQL_Server_Management详解
VS2010自带sql server 2008,但自带的版本缺少SQL_Server_Management,解决如下: 安装的先决条件: 1.SQLManagementStudio_x86_CHS(h ...
- 【内网渗透笔记】Windows2008 R2搭建域控制器
0x00 前言 将网络中的多台计算机逻辑上组织到一起,进行集中管理,这种区别于工作组的逻辑环境叫做域(domain).域是日常计算机管理的一种很有效手段,因此,域控制器自然而然就在成域环境中最重要的角 ...
- /var/spool/postfix/maildrop/ 中有大量的文件
今天查看硬盘剩余的容量,发现‘/’目录下占用了大量的空间:可我在这个目录下面没有放什么东西:仔细查看在/var/spool/postfix/maildrop/ 中发现了大量的文件.怎么会有这么多的文件 ...
- 音频——H5 audio
分享站又有新功能了:将文件站上的语音文件正确播放出来.效果图: 暂停: 播放: 实现的效果:类似于音乐播放器一般,但是较之更简单一些,可以正常播放语音,有拖动.快进后退效果便可. 思路: 首先想到的便 ...
- 【Java并发编程二】同步容器和并发容器
一.同步容器 在Java中,同步容器包括两个部分,一个是vector和HashTable,查看vector.HashTable的实现代码,可以看到这些容器实现线程安全的方式就是将它们的状态封装起来,并 ...