大部分
//創(chuàng)建操作
+ (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:最簡(jiǎn)單的提醒視
//創(chuàng)建操作
UIAlertAction *okAlert = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){//具體操作內(nèi)容}];
//初始化UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"頂部標(biāo)題欄"message:@"中間信息"preferredStyle:UIAlertControllerStyleAlert];
//添加操作
[alert addAction:okAlert];
//以model形式糕再,顯示警告視圖[self presentViewController:alert animated:YES completion:nil];
//等同于NSString *title =@"頂部標(biāo)題欄";
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:多個(gè)按鍵的提醒視圖//取消按鍵——下次下次 UIAlertActionStyleCancel? (粗體)[alert addAction:[UIAlertAction actionWithTitle:@"下次下次"style:UIAlertActionStyleCancel handler:^(UIAlertAction *_Nonnull action) {
NSLog(@"點(diǎn)擊取消按鈕");
}]];
//紅色按鍵——?dú)埲叹芙^ UIAlertActionStyleDestructive
[alert addAction:[UIAlertAction actionWithTitle:@"殘忍拒絕"style:UIAlertActionStyleDestructive handler:^(UIAlertAction *_Nonnull action) {
NSLog(@"紅色按鈕");
}]];
//兩個(gè)會(huì)是這樣//3個(gè)就挨個(gè)往下排//普通按鍵——立馬好評(píng) UIAlertActionStyleDefault[alert addAction:
[UIAlertAction actionWithTitle:@"立馬好評(píng)"style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
NSLog(@"普通按鈕");
}]];
示例3:帶對(duì)話框TextField- (void)addTextFieldWithConfigurationHandler:(void(^ __nullable)(UITextField *textField))configurationHandler;//添加TextField 條欄? addTextFieldWithConfigurationHandler[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
NSLog(@"TextField");//中間的提示輸入textField.placeholder =@"用來提示你做什么事的";
}];
示例4:提醒圖標(biāo)亲配,在最底部呈現(xiàn) Sheet//UIAlertControllerStyleAlert改成UIAlertControllerStyleActionSheet (最后面的)UIAlertController *alert =[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertControllerStyleActionsheet好像不能和TextField在一起镇草,會(huì)報(bào)錯(cuò)。是這樣嗎?