1.设置两个UIAlertController
@property (nonatomic,strong)UIAlertController *alert;
@property (nonatomic,strong)UIAlertController *alert2;
2.通过懒加载创建
-(UIAlertController *)alert
{
if (_alert == nil) {
_alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"可以自定义一些提示框" preferredStyle:UIAlertControllerStyleActionSheet];
//UIAlertControllerStyleActionSheet
//UIAlertControllerStyleAlert
/*
UIAlertActionStyleDefault = 0,
UIAlertActionStyleCancel,
UIAlertActionStyleDestructive
*/
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"action3" style:UIAlertActionStyleDestructive handler:nil];
UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"action4" style:UIAlertActionStyleDestructive handler:nil];
[_alert addAction:action1];
[_alert addAction:action2];
[_alert addAction:action3];
[_alert addAction:action4];
}
return _alert;
}
- (IBAction)btn1:(id)sender {
显示提示框
[self presentViewController:self.alert animated:YES completion:nil];
}
-(UIAlertController *)alert2
{
if (_alert2 == nil) {
_alert2 = [UIAlertController alertControllerWithTitle:@"标题" message:@"可以自定义一些提示框" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[_alert2 addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"密码";
}];
[_alert2 addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"账号";
}];
[_alert2 addAction:action1];
[_alert2 addAction:action2];
}
NSLog(@"----------------->>>");
return _alert2;
}
- (IBAction)btn2:(id)sender {
[self presentViewController:self.alert2 animated:YES completion:nil];
}