iOS 修改alertViewController彈框的字體顏色及字體的方法
更新時間:2018年01月10日 10:24:45 作者:Kaiccy
下面小編就為大家分享一篇iOS 修改alertViewController彈框的字體顏色及字體的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
系統(tǒng)默認(rèn)的字體是黑色,按鈕顏色是藍(lán)色或者紅色的,我們怎樣自定義字體呢
Codeing Show
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"確認(rèn)退出登錄?" 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:@"確認(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"]; [alertVC addAction:cancelAction]; [alertVC addAction:okAction]; [self presentViewController:alertVC animated:YES completion:nil];
這里的kGreenColor 等是我自定義的顏色,換成自己的字體顏色即可
以上這篇iOS 修改alertViewController彈框的字體顏色及字體的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
ios NSNotificationCenter通知的簡單使用
這篇文章主要介紹了ios NSNotificationCenter通知的簡單使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-06-06iOS tableView實現(xiàn)頭部拉伸并改變導(dǎo)航條漸變色
這篇文章主要為大家詳細(xì)介紹了iOS tableView實現(xiàn)頭部拉伸并改變導(dǎo)航條漸變色,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05cmake ios終端下執(zhí)行提示錯誤 iOS version not found, tested: [5.0;5.1;6
這篇文章主要介紹了cmake ios終端下執(zhí)行提示錯誤 iOS version not found, tested: [5.0;5.1;6.0;6.1;7.0;8.3]的解決方案的相關(guān)資料,需要的朋友可以參考下2016-10-10iOS開發(fā)之UITableView左滑刪除等自定義功能
今天來給大家介紹下iOS開發(fā)中UITableView左滑實現(xiàn)微信中置頂,刪除等功能。對大家開發(fā)iOS具有一定的參考借鑒價值,有需要的朋友們一起來看看吧。2016-09-09