UIAlertView以及UIAlertController

来源:互联网 发布:社交网络电影百度网盘 编辑:程序博客网 时间:2024/06/06 07:42

UIAlertView 是iOS2.0之后就出现的。在8.0后逐渐被废除,但现在还是可以使用的。


   UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@“标题

                                                       message:@“警示内容

                                                      delegate:selfcancelButtonTitle:@"确定"

                                             otherButtonTitles:@"取消",nil];

    [alertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];

   

    //下面的两个textFielder根据alert的类型来进行是否设置。否则数组越界崩溃。

   UITextField *text=[alertView textFieldAtIndex:0];

    text.clearButtonMode=UITextFieldViewModeAlways;

    text.placeholder=@"哇哈哈";

//    

   UITextField *text1=[alertView textFieldAtIndex:1];

    text1.clearButtonMode=UITextFieldViewModeAlways;

    text1.placeholder=@"哇哈哈";


    [alertViewshow];

UIAlertControoler 是iOS 8.0之后出现的新技能。

UIAlertControoler可以做出UIAlertView 和 UIActionSheet 

融合了二者而来。


UIAlertController中的UIAlertView实现

   UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"警告"message:@"发生了什么"preferredStyle:UIAlertControllerStyleActionSheet];  

    UIAlertAction *action = [UIAlertActionactionWithTitle:@"警告"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {

        //按钮被点击

        NSLog(@"action click");

   }];

    [alert addAction:action];

   

    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {

         textField.placeholder = @"姓名";

   }];

    

    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {

        textField.placeholder = @"年龄";

   }];

   [selfpresentViewController:alert animated:YEScompletion:^{

        

    }];


UIAlertController中UIActionSheet实现

   UIAlertController  *alertAct = [UIAlertControlleralertControllerWithTitle:@"警告"message:@"发生了什么"preferredStyle:UIAlertControllerStyleActionSheet];

    

    UIAlertAction *aaa = [UIAlertActionactionWithTitle:@"1"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {

        NSLog(@"action sheet click  1");

        

    }];

    [alertActaddAction:aaa];

    

    [alertAct addAction:[UIAlertActionactionWithTitle:@"2"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {

         NSLog(@"action sheet click  2");

     }]];

    

    [selfpresentViewController:alertAct animated:YEScompletion:^{

        

    }];



0 0
原创粉丝点击