美文网首页
UIAlertController 中Message和Title

UIAlertController 中Message和Title

作者: Summer_YJL | 来源:发表于2016-05-10 18:00 被阅读0次

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

相关文章

网友评论

      本文标题:UIAlertController 中Message和Title

      本文链接:https://www.haomeiwen.com/subject/vycglttx.html