iOS 修改AlertViewController彈框的字體顏色及字體的方法

系統(tǒng)默認(rèn)的字體是黑色,按鈕顏色是藍(lán)色或者紅色的,自定義字體如下

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"確認(rèn)退出登錄?" preferredStyle:(UIAlertControllerStyleAlert)];
 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
 NSLog(@"點(diǎn)擊了Cancel");
 [alertVC dismissViewControllerAnimated:YES completion:nil];
 }];
 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 NSLog(@"點(diǎn)擊了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:@"確認(rèn)退出登錄?"];
 [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:kSubTextColor range:NSRangeFromString(@"確認(rèn)退出登錄?")];
 [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSRangeFromString(@"確認(rèn)退出登錄?")];
 [alertVC setValue:alertControllerMessageStr forKey:@"attributedMessage"];
 //修改按鈕字體顏色
 [cancelAction setValue:kGreenColor forKey:@"titleTextColor"];
 [okAction setValue:kGreenColor forKey:@"titleTextColor"];
最后編輯于
?著作權(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)容

  • 1、通過CocoaPods安裝項(xiàng)目名稱項(xiàng)目信息 AFNetworking網(wǎng)絡(luò)請(qǐng)求組件 FMDB本地?cái)?shù)據(jù)庫組件 SD...
    陽明AI閱讀 16,213評(píng)論 3 119
  • 文:選師無憂小編 熱播電視劇《小別離》圍繞中學(xué)生出國展開,講述了三個(gè)家庭面對(duì)青春期的孩子升學(xué)、留學(xué)等抉擇的故事。 ...
    選師無憂平臺(tái)閱讀 446評(píng)論 0 0
  • 這部電影很長,我花了一周才斷斷續(xù)續(xù)看完。 阿甘,一個(gè)不太聰明,耿直,執(zhí)著,有著腿疾的孩子,與我們正常孩...
    沉默的夢想閱讀 793評(píng)論 0 0
  • 人間三月,百花竟放,最適合將身心放逐山野,傾聽詩歌生長的聲音。 是日,忙碌之余難得的閑暇,傾心...
    孤獨(dú)乞丐閱讀 1,355評(píng)論 1 5
  • wicky_ding閱讀 266評(píng)論 0 1

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