iOS 修改alertViewController彈框的字體顏色及字體的方法
更新時間:2018年01月10日 10:24:45 作者:Kaiccy
下面小編就為大家分享一篇iOS 修改alertViewController彈框的字體顏色及字體的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
系統(tǒng)默認的字體是黑色,按鈕顏色是藍色或者紅色的,我們怎樣自定義字體呢
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彈框的字體顏色及字體的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
IOS開發(fā)仿微信右側(cè)彈出視圖實現(xiàn)
這篇文章主要介紹了IOS開發(fā)仿微信右側(cè)彈出視圖實現(xiàn)的相關(guān)資料,希望通過本文能幫助到大家,讓大家實現(xiàn)這樣類似的功能,需要的朋友可以參考下2017-10-10
iOS利用AFNetworking實現(xiàn)文件上傳的示例代碼
本篇文章主要介紹了iOS利用AFNetworking實現(xiàn)文件上傳的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
iOS 條碼及二維碼掃描(從相冊中讀取條形碼/二維碼)及掃碼過程中遇到的坑
本文主要給大家介紹ios中從手機相冊中讀取條形碼和二維碼的問題及解決辦法,需要的朋友參考下2017-01-01

