UIAlertController_AlertView
2016-07-03 23:47
417 查看
@interface ViewController ()<UIAlertViewDelegate> @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 { /* //旧的方式来创建 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"我是警告框" message:@"我是警告狂的内容" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"第三个按钮",nil]; //alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alertView show]; */ //IOS8之后创建方式 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"我是警告框" message:@"内容" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *alertAction1 = [UIAlertAction actionWithTitle:@"第1个按钮" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ NSLog(@"我是第1个按钮"); }]; UIAlertAction *alertAction2 = [UIAlertAction actionWithTitle:@"第2个按钮" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){ NSLog(@"我是第2个按钮"); }]; UIAlertAction *alertAction3= [UIAlertAction actionWithTitle:@"第3个按钮" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action){ NSLog(@"我是第3个按钮"); }]; UIAlertAction *alertAction4= [UIAlertAction actionWithTitle:@"第4个按钮" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ NSLog(@"我是第4个按钮"); }]; //添加按钮 [alertController addAction:alertAction1]; [alertController addAction:alertAction2]; [alertController addAction:alertAction3]; [alertController addAction:alertAction4]; alertController.preferredAction = alertController.actions.lastObject;//首选 高亮 //添加输入框 [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField){ textField.placeholder=@"默认文字"; textField.backgroundColor = [UIColor grayColor]; }]; [self presentViewController:alertController animated:YES completion:nil];//把它放在上面是的话添加输入框不起作用的 } //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // NSLog(@"%d",buttonIndex); //} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- 高性能Key/Value存储引擎levelDB, rocksDB, TiDB,InnoDB
- request的setAttribute()怎么用的?
- StringBuffer和StringBuilder的区别?
- UIScrollView的基本用法
- vue-loader + Webpack 环境搭建
- Android Studio 构建项目卡在 gradle build running
- 【leetcode】303. Range Sum Query - Immutable
- TOJ 3601.Longest Contiguous Subsequence 最长连续公共子序列
- uva 1626 - Brackets sequence dp(区间,坑题, 难度适中,难ac)
- 开发中 十六进制的颜色值直接转为ios可用的UIColor
- Android系统应用---SystemUI之一:SystemUI概述和创建启动流程分析
- 关于UITableView中删除某一行方法的使用
- 修改UITextField的placeholder颜色
- UIStepper
- easyui radio 无法选中的原因
- 使用easyUI遇到的一些小问题
- POJ2299 Ultra-QuickSort
- LeetCode - 111. Minimum Depth of Binary Tree
- UIPageControl
- Deep Reinforcement Learning for Dialogue Generation-关于生成对话的深度强化学习