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中的启动器,把系统当个 ...
随机推荐
- MVC多语言设置 实战简洁版
此方式可以通过更改进行更改进程语言设定,支持从系统获取默认的区域设定,支持自定义,自定义的方式可以为cookie,可为资料库获取,session等方式. 具体怎么设定就看个人需要了. 第一步: 添加资 ...
- Android开发学习笔记-GridView的动态显示
1.添加GridItem布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- jquery.form 和MVC4做无刷新上传DEMO
jquery.form 和MVC4做无刷新上传DEMO HTML: <script src="~/Scripts/jquery-1.10.2.min.js"></ ...
- symfony 命令
1.创建Bundle php bin/console generate:bundle --namespace=Home/IndexBundle --format=yml 创建bundle会更新app ...
- AndroidManifest详解
一,重要性AndroidManifest.xml是Android应用程序中最重要的文件之一.它是Android程序的全局配置文件,是每个 android程序中必须的文件.它位于我们开发的应用程序的根目 ...
- Android零碎知识点 1
Android零碎知识点 1 Android在2.3版本上开始支持KeyEvent.KEYCODE_PAGE_DOWN以及KeyEvent.KEYCODE_PAGE_UP的操作. Androi ...
- 【Android】java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'.
一.问题 Java调用JS事件出现 java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on th ...
- VS无法导航到插入点F12失败
关闭VS 开启控制台并导航到Visual安装文件夹,例如C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\ID ...
- 【重要】U3D存放本地游戏存档——不同平台载入XML文件的方法——IOS MAC Android
在PC上和IOS上读取XML文件的方式略有差别,经测试,IOS上不支持如下方法载入XML文件: XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load( ...
- Pycharm按装
1.python 官方 2.下载完成后点击exe 安装 3.按装完成后在cmd中输入 python 1.如果显示python版本 那么就安装成功 2.如果出现"python"不是外 ...