关于UIAlertController的使用

来源:互联网 发布:淘宝店铺综合评分497 编辑:程序博客网 时间:2024/05/21 17:39

由于IOS9舍弃了一直使用的UIAlert,突然有点不习惯,想比之下UIAlert更加方便,设置一下,一个show就行了

账号密码类可以模态视图弹出,更多的第三方推送也使得不得不进行模态视图。但是取消了,还是有点可惜的。

UIAlertController因为是个视图控制器,所以跟方便的添加更多控件,今天研究了一下。


    //初始化提示框视图    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"这是内容" preferredStyle:UIAlertControllerStyleAlert];    //取消按钮,但是取消按钮同哟个提示框视图内只允许有一个    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {        /**         *  点击过后执行此段代码         *  在主线程中执行该段代码         *  代码块action参数为点击的按钮         */            }];        //确定按钮/*    UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {            }];     [alertController addAction:okAction];*/        //警告按钮,设置警告按钮模式时,系统默认将按钮颜色置成红色    UIAlertAction * restAction = [UIAlertAction actionWithTitle:@"重置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action)    {            }];    //将两个按钮加入提示框视图中    [alertController addAction:restAction];    [alertController addAction:cancelAction];    //推出视图    [self presentViewController:alertController animated:YES completion:^{            }];

下部上拉视图

看cocoaChain说取消键已经被取消了。。。改为点击屏幕其他相应


 //创建一个上拉菜单    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"我是标题" message:@"这里是文本信息" preferredStyle:UIAlertControllerStyleActionSheet];        //取消按钮,无论怎么创建,都在最下方    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消按钮" style:UIAlertActionStyleCancel handler:nil];    [alertController addAction:cancelAction];        //删除按钮,无论怎么创建,都再最上方,而且是红色    UIAlertAction * deleteAction = [UIAlertAction actionWithTitle:@"删除按钮" style:UIAlertActionStyleDestructive handler:nil];    [alertController addAction:deleteAction];        //其他按钮,并没有什么不一样的    UIAlertAction * otherAction = [UIAlertAction actionWithTitle:@"其他按钮" style:UIAlertActionStyleDefault handler:nil];    [alertController addAction:otherAction];        [self presentViewController:alertController animated:YES completion:nil];        //在方法中dismiss视图删除


0 0
原创粉丝点击