iOS 8新特性—— UIAlertController
2015-11-28 19:37
471 查看
// // ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //危险操作:弹框提醒 //1.UIAlertView // [self alertView]; //2.UIActionSheet // [self actionSheet]; //iOS 8开始:UIAlertController == UIAlertView + UIAcitonSheet // UIAlertControllerStyleActionSheet = 0, // UIAlertControllerStyleAlert UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"警告" message:@"你有严重的精神病" preferredStyle:UIAlertControllerStyleAlert]; //添加文本框 [ac addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.textColor = [UIColor redColor]; textField.text = @"123"; //监听textField文字的改变 [textField addTarget:self action:@selector(usernameDidChange:) forControlEvents:UIControlEventEditingChanged]; }]; [ac addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.secureTextEntry = YES; textField.text = @"password"; }]; //添加按钮 __weak typeof (ac) weakAc = ac; [ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { NSLog(@"点击了确定按钮--%@--%@", [weakAc.textFields.firstObject text], [weakAc.textFields.lastObject text]); }]]; [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"点击了取消按钮"); }]]; //弹出 [self presentViewController:ac animated:YES completion:nil]; } /** * 监听textField文字的改变 */ - (void)usernameDidChange:(UITextField *)usename { NSLog(@"usename=%@",usename.text); } - (void)actionSheet { UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"警告" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"关闭", nil]; [sheet showInView:self.view]; } - (void)alertView { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"警告" message:@"你有严重的精神病" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; //加一个密码文本框 alert.alertViewStyle = UIAlertViewStyleSecureTextInput; [alert show]; } @end
相关文章推荐
- Building Simulation Packet-Loss System in Channel
- 我的iOS学习历程 - UITabBarViewController
- 为什么Java中1000==1000为false而100==100为true?
- UESTC 65 CD Making 贪心法
- UI-之plist文件解析
- 【Leetcode】N-Queens II
- UINavigationController设置导航栏属性
- 【Leetcode】N-Queens
- UITabBarController
- Codeforces 288E Polo the Penguin and Lucky Numbers
- UITableView 的结构
- 使用druid连接池的超时回收机制排查连接泄露问题
- 在Legacy BIOS与UEFI 两种模式安装Windows 8操作系统的方法
- iOS 9人机界面指南:UI设计基础--模态情景(Modal Contexts)
- HDFS Short-Circuit Local Reads
- iOS流布局UICollectionView系列一——初识与简单使用UICollectionView
- Duilib源码分析(四)绘制管理器—CPaintManagerUI—(前期准备四)
- easyui datagrid 表格组件列属性formatter和styler使用方法
- 导航栏控制器和标签栏控制器(UINavigationController和UITabBarController)混用
- codeforces B.Queries about less or equal elements