改變UILabel部分顏色屬性以及UIAlertController

1.改變label的部分顏色

 UILabel  *textLabel = [UILabel alloc] init];                                                                                                    
 textLabel.textColor = TextGrayColor;
 textLabel.font = [UIFont systemFontOfSize:12];
 NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"網(wǎng)址是:https://www.baidu.com"];
//更改字體  
 [string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20] range:NSMakeRange(4, 21)];  
//修改顏色
 [string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(4, 21)];
 textLabel.attributedText = string;

2.改變UIAlertController的控件屬性顏色

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示內(nèi)容" preferredStyle:UIAlertControllerStyleAlert];
//UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示內(nèi)容" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Default" style:UIAlertActionStyleDefault handler:nil];  
UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"Destructive" style:UIAlertActionStyleDestructive handler:nil];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];

[alertController addAction:defaultAction];
[alertController addAction:destructiveAction];
[alertController addAction:cancelAction];

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


//修改title
NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];
[alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
[alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
[alertController setValue:alertControllerStr forKey:@"attributedTitle"];

//修改message
NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"提示內(nèi)容"];
[alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 4)];
[alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 4)];
[alertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];
//修改按鈕
if (cancelAction valueForKey:@"titleTextColor") {
    [cancelAction setValue:[UIColor redColor] 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),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,062評(píng)論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,375評(píng)論 4 61
  • 1、窗體 1、常用屬性 (1)Name屬性:用來(lái)獲取或設(shè)置窗體的名稱,在應(yīng)用程序中可通過Name屬性來(lái)引用窗體。 ...
    Moment__格調(diào)閱讀 4,782評(píng)論 0 11
  • 由于沒注意看通知,不知道小區(qū)停天然氣,結(jié)果臨時(shí)被動(dòng)了,女兒說(shuō):“我好像有看到?!蔽艺f(shuō):“那你為什么不早說(shuō)呢?...
    不知有漢驥無(wú)論魏晉章閱讀 101評(píng)論 0 0
  • 這世界上 有三件事永遠(yuǎn)無(wú)法隱瞞: 咳嗽、貧窮和愛 當(dāng)你對(duì)一個(gè)人有了愛意 即使捂住了嘴巴 也會(huì)從眼睛里冒出來(lái) 萬(wàn)千心...
    權(quán)權(quán)大大閱讀 1,453評(píng)論 0 1

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