UIAlertController 中Message和Title文字屬性設置

1.設置

2.富文本

//1.修改title

NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"物品詳情"];

[alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)]; ?//物品2個字為紅色

[alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)]; ??

[alertController setValue:alertControllerStr forKey:@"attributedTitle"];

//2.修改message

NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"輕便的移動電源很容易就電量耗盡,而大容量的移動電源往往都比較笨重,這樣的體驗遠遠比不上直接更換電池。"];

[alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 10)];

[alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(11, 20)];

[alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(20, 30)];

[alertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];

//3.修改按鈕的顏色

[cancelAction setValue:[UIColor orangeColor] forKey:@"titleTextColor"];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容