UIAlertController 弹框

一. 标准的Alert样式

//UIAlertController风格:UIAlertControllerStyleAlert
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"主标题" message:@"提示文字"preferredStyle:UIAlertControllerStyleAlert ];

//添加取消到UIAlertController中
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:cancelAction];

//添加确定到UIAlertController中
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:OKAction];

[self presentViewController:alertController animated:YES completion:nil]

二. 标准的Alert Sheet样式

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标准的Action Sheet样式" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//取消:style:UIAlertActionStyleCancel//
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
//了解更多:style:UIAlertActionStyleDestructive
UIAlertAction *moreAction = [UIAlertAction actionWithTitle:@"了解更多" style:UIAlertActionStyleDestructive handler:nil];
[alertController addAction:moreAction];
//原来如此:style:UIAlertActionStyleDefault
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"原来如此" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:OKAction];

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

三. 新功能

style:UIAlertActionStyleDefault//对按钮应用标准样式
style:UIAlertActionStyleCancel//对按钮应用取消样式,即取消操作
style:UIAlertActionStyleDestructive//对按钮应用警示性样式,提示用户这样做可能会删除或者改变某些数据


UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"主标题:标题党"message:@"子标题:提示信息" preferredStyle:UIAlertControllerStyleAlert ];
//取消style:UIAlertActionStyleDefault
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:cancelAction];

//style:UIAlertActionStyleDestructive(警告提示)
UIAlertAction *rubbishAction = [UIAlertAction actionWithTitle:@"确定修改" style:UIAlertActionStyleDestructive handler:nil];
[alertController addAction:rubbishAction];

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

四. 弹出文本框

// 只有在alert情况下才可以添加文本框
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"用户名";
        textField.secureTextEntry = YES;
    }];

//    // 取出文本
//    UITextField *text = alertController.textFields.firstObject;
//    UIAlertAction *action = alertController.actions.firstObject;