通过私有的成员变量修改AlertController的title属性

128 阅读1分钟
/*title*/

NSMutableAttributedString*alertTitleStr = [[NSMutableAttributedStringalloc]initWithString:@"提示"];

[alertTitleStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:20]range:NSMakeRange(0,2)];

[alertTitleStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(0,2)];

[alertControllersetValue:alertTitleStrforKey:@"attributedTitle"];

/*message*/

NSMutableAttributedString*alertMessageStr = [[NSMutableAttributedStringalloc]initWithString:@"请修改输入内容"];

[alertMessageStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:18]range:NSMakeRange(0,7)];

[alertMessageStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColororangeColor]range:NSMakeRange(0,3)];

[alertMessageStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorgreenColor]range:NSMakeRange(3,2)];

[alertMessageStraddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(5,2)];

[alertControllersetValue:alertMessageStrforKey:@"attributedMessage"];

/*取消按钮的颜色*/

[cancelsetValue:[UIColorredColor]forKey:@"_titleTextColor"];

[alertControlleraddAction:cancel];

[alertControlleraddAction:okAction];