UIAlertController的使用

来源:互联网 发布:知乎入门级古典音乐 编辑:程序博客网 时间:2024/06/06 00:05

样式一:



UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    

    UIAlertAction* phone = [UIAlertAction actionWithTitle:@"客服-4006200365" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"4006200365"];

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

    }];

    

    UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

    

    [alert addAction:phone];

    [alert addAction:cancel];

    

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





样式二:





 

  UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:@"权限码(参见出厂文件Admin Code)" preferredStyle:UIAlertControllerStyleAlert];

    

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

        textField.placeholder = @"权限码(参见出厂文件Admin Code)";

    }];

    

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

        textField.placeholder = @"000000";

        textField.secureTextEntry = YES;

    }];

    

    UIAlertAction* confirm = [UIAlertAction actionWithTitle:@"确定 Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        //

    }];

    

    UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"取消 Cancel" style:UIAlertActionStyleCancel handler:nil];

    

    [alert addAction:confirm];

    [alert addAction:cancel];

    

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


原创粉丝点击