溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS如何修改alertViewController彈框的字體顏色及字

發(fā)布時間:2021-06-28 13:40:06 來源:億速云 閱讀:256 作者:小新 欄目:移動開發(fā)

這篇文章主要介紹了iOS如何修改alertViewController彈框的字體顏色及字,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

Codeing Show

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"確認退出登錄?" preferredStyle:(UIAlertControllerStyleAlert)];
 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
 NSLog(@"點擊了Cancel");
 [alertVC dismissViewControllerAnimated:YES completion:nil];
 }];
 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 NSLog(@"點擊了OK");
 [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kLoginUserKey];
 [alertVC dismissViewControllerAnimated:YES completion:nil];
 }];
 //修改title
 NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];
 [alertControllerStr addAttribute:NSForegroundColorAttributeName value:kMainTextColor range:NSMakeRange(0, 2)];
 [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 2)];
 [alertVC setValue:alertControllerStr forKey:@"attributedTitle"];
 //修改message
 NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"確認退出登錄?"];
 [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:kSubTextColor range:NSRangeFromString(@"確認退出登錄?")];
 [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSRangeFromString(@"確認退出登錄?")];
 [alertVC setValue:alertControllerMessageStr forKey:@"attributedMessage"];
 //修改按鈕字體顏色
 [cancelAction setValue:kGreenColor forKey:@"titleTextColor"];
 [okAction setValue:kGreenColor forKey:@"titleTextColor"];
 [alertVC addAction:cancelAction];
 [alertVC addAction:okAction];
 [self presentViewController:alertVC animated:YES completion:nil];

這里的kGreenColor 等是我自定義的顏色,換成自己的字體顏色即可

感謝你能夠認真閱讀完這篇文章,希望小編分享的“iOS如何修改alertViewController彈框的字體顏色及字”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

ios
AI