iOS9 UIAlertController简单使用代码
2016-02-29 11:14
417 查看
iOS9 xcode7以后,很多方法都过期了,被新的方法所代替。在这里我主要介绍两个常用的控件——UIAlertView、UIActionSheet被替代的新控件——UIAlertController的使用。
一、UIAlertController的UIActionSheet效果时的用法
UIAlertController * sheet = [UIAlertControlleralertControllerWithTitle:nilmessage:@"选择性别"preferredStyle:UIAlertControllerStyleActionSheet];
[sheetaddAction:[UIAlertActionactionWithTitle:@"男"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {
NSLog(@"在这里处理选择之后的事");
}]];
[sheet addAction:[UIAlertActionactionWithTitle:@"女"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {
NSLog(@"在这里处理选择之后的事");
}]];
[sheetaddAction:[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil]];
[selfpresentViewController:sheetanimated:YEScompletion:nil];
二、UIAlertController的UIAlertView效果时的用法
UIAlertController * alert = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"请输入手机号"preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"确定"style:(UIAlertActionStyleCancelhandler:^(UIAlertAction
*action) {
NSLog(@"在这里处理点击按钮之后的事");
}];
[alert addAction:okAction];
[selfpresentViewController:alert
animated:YEScompletion:nil];
一、UIAlertController的UIActionSheet效果时的用法
UIAlertController * sheet = [UIAlertControlleralertControllerWithTitle:nilmessage:@"选择性别"preferredStyle:UIAlertControllerStyleActionSheet];
[sheetaddAction:[UIAlertActionactionWithTitle:@"男"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {
NSLog(@"在这里处理选择之后的事");
}]];
[sheet addAction:[UIAlertActionactionWithTitle:@"女"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {
NSLog(@"在这里处理选择之后的事");
}]];
[sheetaddAction:[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil]];
[selfpresentViewController:sheetanimated:YEScompletion:nil];
二、UIAlertController的UIAlertView效果时的用法
UIAlertController * alert = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"请输入手机号"preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"确定"style:(UIAlertActionStyleCancelhandler:^(UIAlertAction
*action) {
NSLog(@"在这里处理点击按钮之后的事");
}];
[alert addAction:okAction];
[selfpresentViewController:alert
animated:YEScompletion:nil];
相关文章推荐
- [Locked] Range Sum Query 2D - Mutable
- UIKit框架(7)应用程序对象UIApplication
- unique函数
- UITableView 学习整理
- 关于kendo ui的使用改变颜色方式
- 限定UITextfield的输入字符的格式和字数
- UIBUtton 的两种图片设置
- UIBUtton 的两种图片设置
- 十八、UiAutomator 相关JAVA知识
- iOS蓝牙4.0 CoreBluetooth框架开发
- Android优化——UI优化(五) Listview 重用convertView
- UISwitch控件修改大小。设置颜色
- UIKit框架(6)控制器view的加载方式
- [转] DBCP 的validationQuery
- ueditor 配置和上传图片
- 别人的jqueyr解读
- UITableview里面对于分割线显示整个屏幕宽度的设置
- 【LeetCode】96. Unique Binary Search Trees
- Android优化——UI优化(四) 使用stytle
- Android优化——UI优化(三)使用ViewStub延迟加载