IOS UIAlertController 弹框 (ios 9.0 后代替了UIAlertView弹框 和 UIActionSheet下弹框)
2016-03-04 10:25
585 查看
在IOS 9.0 后 苹果官方宣布不再或不推荐使用UIAlertView 和 UIActionSheet 由UIAlertController进行代替两者 用控制器将两者合二为一 很简单 方便 下面就是关于UIAlertView的常用方法
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // 创建一个BUTTON 点击显示弹框 UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)]; button.frame = CGRectMake(100, 100, 100, 100); // 给BUTTON 添加点击方法 [button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchUpInside)]; button.backgroundColor = [UIColor blueColor]; [self.view addSubview:button]; } // button的点击方法 - (void)actionButton:(UIButton *)button { // 初始化一个一个UIAlertController // 参数preferredStyle:是IAlertController的样式 // UIAlertControllerStyleAlert 创建出来相当于UIAlertView // UIAlertControllerStyleActionSheet 创建出来相当于 UIActionSheet UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"静" preferredStyle:(UIAlertControllerStyleAlert)]; // 创建按钮 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { NSLog(@"注意学习"); }]; // 创建按钮 // 注意取消按钮只能添加一个 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) { // 点击按钮后的方法直接在这里面写 NSLog(@"注意学习"); }]; // // 创建警告按钮 // UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction *action) { // NSLog(@"注意学习"); // }]; // // 添加按钮 将按钮添加到UIAlertController对象上 [alertController addAction:okAction]; [alertController addAction:cancelAction]; //[alertController addAction:structlAction]; // 只有在alert情况下才可以添加文本框 [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"用户名"; textField.secureTextEntry = YES; }]; // // 取出文本 // UITextField *text = alertController.textFields.firstObject; // UIAlertAction *action = alertController.actions.firstObject; // 将UIAlertController模态出来 相当于UIAlertView show 的方法 [self presentViewController:alertController animated:YES completion:nil]; }
相关文章推荐
- android requestWindowFeature使用详解
- 从源码分析 对 非UI线程不允许访问UI元素的 理解
- UIAutomator remote debug方法
- Uiautomator使用
- EasyUI 的各种提示框消息框配置
- Android Studio 中遇到的Gradle build插件版本太低的问题:Plugin is too old
- SVN UUID 变更导致提交更新错误
- UIScrollView之检测滚动方向
- iOS学习笔记67-UIBezierPath精讲
- 慎用PHP$_REQUEST数组
- web开发中,需要用到的脚本---jque…
- PHP $_SERVER["QUERY_ST…
- question_018-JAVA之Map之TreeMap键为自定义对象
- mysqli->multi_query()多条语句的…
- mysqli_query和mysql_query有何区…
- include require include_on…
- UISearchController使用方法及注意事项
- 用xib自定义UITableViewCell的注意事项——重用问题
- LeetCode-60-Permutation Sequence(找规律)-Medium
- 自定义UITabBarController标签视图控制器