登錄注冊(cè)

大部分

//創(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 =@"用來(lái)提示你做什么事的";

}];

示例4:提醒圖標(biāo),在最底部呈現(xiàn) Sheet//UIAlertControllerStyleAlert改成UIAlertControllerStyleActionSheet (最后面的)UIAlertController *alert =[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertControllerStyleActionsheet好像不能和TextField在一起,會(huì)報(bào)錯(cuò)。是這樣嗎?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容