iOS 對(duì)系統(tǒng)的提示框進(jìn)行簡單的修改


------??? 帶有輸入框的提示框? ------

有時(shí)候 , 我們需要帶有輸入框的提示框, 如圖:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"請(qǐng)輸入個(gè)人信息" preferredStyle:UIAlertControllerStyleAlert];

[alertController addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

UITextField *userNameTextField = alertController.textFields.firstObject;

UITextField *passwordTextField = alertController.textFields.lastObject;

NSLog(@"用戶名 = %@,密碼 = %@",userNameTextField.text,passwordTextField.text);

}]];

[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];

[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

textField.placeholder = @"請(qǐng)輸入用戶名";

}];

[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

textField.placeholder = @"請(qǐng)輸入密碼";

}];

[self presentViewController:alertController animated:true completion:nil];


------? 修改系統(tǒng)提示框的字號(hào)和顏色等屬性 ------



UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"提示信息" preferredStyle:UIAlertControllerStyleAlert];

//修改標(biāo)題的內(nèi)容,字號(hào),顏色。使用的key值是“attributedTitle”

NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"提示"];

[hogan addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:40] range:NSMakeRange(0, [[hogan string] length])];

[hogan addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [[hogan string] length])];

[alertController setValue:hogan forKey:@"attributedTitle"];

//修改按鈕的顏色,同上可以使用同樣的方法修改內(nèi)容,樣式

UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Default" style:UIAlertActionStyleDefault handler:nil];

[defaultAction setValue:[UIColor grayColor] forKey:@"_titleTextColor"];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];

[cancelAction setValue:[UIColor greenColor] forKey:@"_titleTextColor"];

[alertController addAction:defaultAction];

[alertController addAction:cancelAction];

[self presentViewController:alertController animated:YES completion:nil];

------? 改變提示文字的顏色? ------

這個(gè)是系統(tǒng)自帶的,? 只是改變了提示框的展示樣式.

UIAlertActionStyleDestructive


//顯示彈出框列表選擇

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title"

message:@"This is an Sheet."

preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消"

style:UIAlertActionStyleCancel

handler:^(UIAlertAction * action) {

//響應(yīng)事件

NSLog(@"action = %@", action);

}];

UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"刪除"

style:UIAlertActionStyleDestructive

handler:^(UIAlertAction * action) {

//響應(yīng)事件

NSLog(@"action = %@", action);

}];

UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"保存"

style:UIAlertActionStyleDefault

handler:^(UIAlertAction * action) {

//響應(yīng)事件

NSLog(@"action = %@", action);

}];

[alert addAction:saveAction];

[alert addAction:cancelAction];

[alert addAction:deleteAction];

[self presentViewController:alert animated:YES completion:nil];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容