(10)UIAlterController与UIAlterAction

(一)UIAlterController是“提示框”的意思

  1.iOS7使用UIAlertView,iOS8使用的是 UIAlertController
      
       UIAlterController继承于UIViewController,说白了也是一个控制器,他的显示只是提示框而已,不像其他控制器可以拥有一个随意的View

(二).UIAlterController具有两种表现形式(风格)

       UIAlterController有两种风格(弹出方式采取的是模态模式,也就是present,具体的看下面的代码)
      
      (1)UIAlertControllerStyleActionSheet = 0,显示在底部   不支持输入框
       
       例如:UIAlterController *alterController = [UIAlterController alertControllerWithTitle:@"进入下一页" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

      (2)UIAlertControllerStyleAlert   显示在屏幕中间

       例如:           
           UIAlertController *alterController = [UIAlertController alertControllerWithTitle:@"你是个好人吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];

      (3)上面的两步仅仅是设定一个提示框,要想显示提示框还要加上模态转换进入我们所设置的UIAlterController的界面(此时只是点击屏幕只是出现一个提示框而已,而且不能够返回)

         [self presentViewController:alterController animated:YES completion:nil];

      (4)上面代码的总体展示
    
          -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
         {
          
             UIAlterController *alterController = [UIAlterController alertControllerWithTitle:@"进入下一页" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

             [self presentViewController:alterController animated:YES completion:nil];

         }

(三)UIAlterAction的讲解(类似于Button)

    (1).有三种形式,下面分别介绍
    
        1. UIAlertActionStyleDefault 
                                        
        2. UIAlertActionStyleCancel  取消(加在提示框上,点击界面,可以自动返回,也可以点击取消返回上一个界面)
                                        
        3. UIAlertActionStyleDestructive  字体会标红,表示一个提醒 //Destructive:有破坏性的


     (2).对上面的三种形式分别举例

            1.例如(可以点击自动返回,因为自带dismiss )
               UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"进入下一页" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

                UIAlertAction *addaction1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    
                }];

               [alertVc addAction:addaction1];

               [self presentViewController:alertVc animated:YES completion:nil];

            2.例如(加在提示框上可以点击屏幕自动返回上一个界面,也可以点击取消返回)

               UIAlertAction *cancelAction1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    
               }];

               [alertVc addAction:cancelAction1];

            3.例如 (UIAlertActionStyleDestructive 字体会标红,表示一个提醒,可以用于删除按钮的设置)
               UIAlertAction *cancelAction3 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
          
              }];

              [alertVc addAction:cancelAction3];

      (3)在提示框里面还可以设置UITextFiled的(直接添加不再需要其他的做法)

             [alertVc addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

             [textField addTarget:self action:@selector(contentChange:) forControlEvents: UIControlEventEditingChanged];
    
             }];

       (4)UITextFiled不可以在UIAlterController在下面弹出的输入框赋赋值,但是在中间弹出的可以赋值

这是一些简单的介绍,水平有限,望大家多指正,下节课讲述UIAlterController与UIAlterAction,UIImagePickerController 的综合运用。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容