一、创建一个UIAlertController
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"用户名或密码错误!" message:@"请多次尝试!" preferredStyle:UIAlertControllerStyleAlert];
二、创建一个或多个UIAlertAction
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"action1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"action1");
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"action2" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"action2");
}];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"action3" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"action3");
}];
UIAlertActionStyleDefault 默认样式
UIAlertActionStyleCancel 取消
UIAlertActionStyleDestructive 删除样式(红色)
三、添加Action
[controller addAction:action1];
[controller addAction:action2];
[controller addAction:action3];
四、关键代码
[self presentViewController:controller animated:YES completion:^{
}];