iOS开发 - UIAlertController 弹框提醒
来源:互联网 发布:帝国主义算法 编辑:程序博客网 时间:2024/05/17 03:37
传统的alertView
- (void)alertView{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"你的操作时非法的,您要继续吗" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alert show];}
传统的actionSheet
- (void)actionSheet{ UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"警告:你的操作时非法的,您要继续吗" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"关闭", nil]; [sheet showInView:self.view]; }
UIAlertController == UIAlertView + UIActionSheet
- (void)alertController{ // 危险操作:弹框提醒 // 1.UIAlertView // 2.UIActionSheet // iOS8开始:UIAlertController == UIAlertView + UIActionSheet UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"你的操作时非法的,您要继续吗" preferredStyle:UIAlertControllerStyleAlert]; // 添加按钮 __weak typeof(alert) weakAlert = alert; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"点击了确定按钮--%@-%@", [weakAlert.textFields.firstObject text], [weakAlert.textFields.lastObject text]); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"点击了取消按钮"); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"其它" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"点击了其它按钮"); }]]; // 添加文本框 [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.textColor = [UIColor redColor]; textField.text = @"123"; [textField addTarget:self action:@selector(usernameDidChange:) forControlEvents:UIControlEventEditingChanged]; // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(usernameDidChange:) name:UITextFieldTextDidChangeNotification object:textField]; }]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.secureTextEntry = YES; textField.text = @"123"; }]; [self presentViewController:alert animated:YES completion:nil];}- (void)usernameDidChange:(UITextField *)username{ NSLog(@"%@", username.text);}
其他操作
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"你的操作时非法的,您要继续吗" preferredStyle:UIAlertControllerStyleActionSheet]; // 设置popover指向的item alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem; // 添加按钮 [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"点击了确定按钮"); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"点击了取消按钮"); }]]; [self presentViewController:alert animated:YES completion:nil];}// UIAlertControllerStyleActionSheet的使用注意// 1.不能有文本框// 2.在iPad中,必须使用popover的形式展示// Text fields can only be added to an alert controller of style UIAlertControllerStyleAlert// 只能在UIAlertControllerStyleAlert样式的view上添加文本框
0 0
- iOS开发 - UIAlertController 弹框提醒
- iOS开发UI -- UIAlertController(提示框)
- iOS开发-UIAlertController
- iOS开发--自定义UIAlertController
- iOS 开发之UIAlertController
- IOS开发之UIAlertController
- IOS开发之UIAlertController
- iOS开发-UIActionSheet和UIAlertController
- iOS开发进阶-UIAlertController使用
- iOS UIAlertController提示框
- iOS开发 提示框UIAlertController的略微封装
- IOS开发 版本提醒
- iOS UIAlertController弹窗效果
- iOS UIAlertController 弹出框控制器
- iOS UIAlertController 警告框详解
- iOS UIAlertController提示框控制器
- IOS开发之IOS8.0最新UIAlertController
- iOS开发-------UIAlertController(弹出视图控制器)
- github使用中的一些问题
- 奇怪的排序 nyoj 540
- OLAP引擎——Kylin介绍
- Windows中的宽字符串处理问题
- Windows平台搭建Kafka源代码开发环境(Eclipse版本)
- iOS开发 - UIAlertController 弹框提醒
- hdu5424 Rikka with Graph II(n个点n条边的图判哈密顿通路)
- PCIE协议解析 synopsys IP Configuration Space Header 读书笔记(9)
- UVa 1647 - Computer Transformation(找规律+递推)
- swift详解之十七-----------GCD的一些高级用法
- Redis的订阅和发布代码
- 正则表达式
- STL源码剖析 [容器](五)[stl_stack.h]
- centos7环境下mariadb的主从复制