登录注册

大部分

//创建操作

+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void(^ __nullable)(UIAlertAction *action))handler;

//初始化

+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;

//添加操作- (void)addAction:(UIAlertAction *)action;

示例1:最简单的提醒视

//创建操作

UIAlertAction *okAlert = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){//具体操作内容}];

//初始化UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"顶部标题栏"message:@"中间信息"preferredStyle:UIAlertControllerStyleAlert];

//添加操作

[alert addAction:okAlert];

//以model形式,显示警告视图[self presentViewController:alert animated:YES completion:nil];

//等同于NSString *title =@"顶部标题栏";

NSString*message =@"中间信息";

NSString*okAlertButton =@"OK";

UIAlertAction*okAlert =[UIAlertAction

actionWithTitle:okAlertButton style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *_Nonnull action) {

}];

UIAlertController*alert =[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];

示例2:多个按键的提醒视图//取消按键——下次下次 UIAlertActionStyleCancel  (粗体)[alert addAction:[UIAlertAction actionWithTitle:@"下次下次"style:UIAlertActionStyleCancel handler:^(UIAlertAction *_Nonnull action) {

NSLog(@"点击取消按钮");

}]];

//红色按键——残忍拒绝 UIAlertActionStyleDestructive

[alert addAction:[UIAlertAction actionWithTitle:@"残忍拒绝"style:UIAlertActionStyleDestructive handler:^(UIAlertAction *_Nonnull action) {

NSLog(@"红色按钮");

}]];

//两个会是这样//3个就挨个往下排//普通按键——立马好评 UIAlertActionStyleDefault[alert addAction:

[UIAlertAction actionWithTitle:@"立马好评"style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {

NSLog(@"普通按钮");

}]];

示例3:带对话框TextField- (void)addTextFieldWithConfigurationHandler:(void(^ __nullable)(UITextField *textField))configurationHandler;//添加TextField 条栏  addTextFieldWithConfigurationHandler[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {

NSLog(@"TextField");//中间的提示输入textField.placeholder =@"用来提示你做什么事的";

}];

示例4:提醒图标,在最底部呈现 Sheet//UIAlertControllerStyleAlert改成UIAlertControllerStyleActionSheet (最后面的)UIAlertController *alert =[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertControllerStyleActionsheet好像不能和TextField在一起,会报错。是这样吗?

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容