// UIAlertController实例化方法
+(instancetype)alertControllerWithTitle:(nullable NSString *)title meaasge:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
-(void)addAction:(UIAlertAction *)action;
// 在界面上显示提醒信息
-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^__nullable)(void))completion;
// 提醒主要有两种样式,一种是显示在屏幕中央的,另外一种是显示在屏幕底部的。
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = 0;
UIAlertControllerStyleAlert
}
// UIAlertAction是定义提醒每个按钮的样式以及用户点击后所执行的操作,每个UIAlertAction对象都需要添加到一个UIAlertController对象上才能生效。
+(instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;
// 每个提醒的按钮样式也是可以定制的
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
UIAlertActionStyleDefault = 0;
UIAlertActionStyleCancel,
UIAlertActionDestructive
}
-(void)viewDidLoad:(BOOL)animated {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示信息" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitlle:@"YES" style:UIAlertActionStyleDefault handler:^(UIA;ertAction *action) {
MSLog(@" ");
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitlle:@"NO" style:UIAlertActionStyleCancel handler:^(UIA;ertAction *action) {
MSLog(@" ");
}];
[alert addAction:defaultAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}