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中的启动器,把系统当个 ...
随机推荐
- SQL随机生成6位数字
SELECT RIGHT(100000000 + CONVERT(bigint, ABS(CHECKSUM(NEWID()))), 6)
- mysql中json_replace函数的使用?通过json_replace对json对象的值进行替换
需求描述: 在看mysql中关于json的内容,通过json_replace函数可以实现对json值的替换, 在此记录下. 操作过程: 1.查看带有json数据类型的表 mysql> selec ...
- The confusion about jsp four scopes and ServletContext,HttpSession,HttpServletReqest,PageContext
The jsp four scopes are same with ServletContext,HttpSession,HttpServletRequest,PageContext? How ser ...
- Java通过复选框控件数组实现添加多个复选框控件
编写程序,通过复选框控件数组事先选择用户爱好信息的复选框,在该程序中,要求界面中的复选框数量可以根据指定复选框名称的字符串数组的长度来自动调节. 思路如下: 创建JPanel面板对象: 使用JPane ...
- MessageDigest类提供MD5或SHA等加密算法
MessageDigest可使用的加密方法有MD2\MD5\SHA-1\SHA-256\SHA-384\SHA-512,使用时候只替换相应参数值即可 MessageDigest md5 = Messa ...
- python线程池(threadpool)
一.安装 pip install threadpool 二.使用介绍 (1)引入threadpool模块 (2)定义线程函数 (3)创建线程 池threadpool.ThreadPool() (4)创 ...
- [ZZ]c++ cout 格式化输出浮点数、整数及格式化方法
C语言里可以用printf(),%f来实现浮点数的格式化输出,用cout呢...?下面的方法是在网上找到的,如果各位有别的办法谢谢留下... iomanip.h是I/O流控制头文件,就像C里面的格式化 ...
- jquery 动态展示查询条件
<table class="queryTable" width="100%" > <tr> <td class="que ...
- flask livereload用法
#coding=utf-8 from flask import Flask from flask_script import Manager app = Flask(__name__) manager ...
- MVC的路由设置【转】
转,MVC的路由设置. 后端获取路由里面action的参数,函数需要设置相同的参数名称才行. routes.MapRoute( "Default", "{controll ...