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"];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容