UIAlertController*alert = [UIAlertControlleralertControllerWithTitle:@"标题"message:@"内容"preferredStyle:UIAlertControllerStyleAlert];
//使用富文本来改变alert的title字体大小和颜色
NSMutableAttributedString*title = [[NSMutableAttributedStringalloc]initWithString:@"这里是标题"];
[titleaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:24]range:NSMakeRange(0,2)];
[titleaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(0,2)];
[alertsetValue:titleforKey:@"attributedTitle"];
//使用富文本来改变alert的message字体大小和颜色
// NSMakeRange(0, 2)代表:从0位置开始两个字符
NSMutableAttributedString*message = [[NSMutableAttributedStringalloc]initWithString:@"这里是正文信息"];
[messageaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:10]range:NSMakeRange(0,6)];
[messageaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(0,2)];
[messageaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorbrownColor]range:NSMakeRange(3,3)];
[alertsetValue:messageforKey:@"attributedMessage"];
UIAlertAction*cancelAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil];
//设置按钮背景图片
UIImage*accessoryImage = [[UIImageimageNamed:@"3.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[cancelActionsetValue:accessoryImageforKey:@"image"];
//设置按钮的title颜色
[cancelActionsetValue:[UIColorlightGrayColor]forKey:@"titleTextColor"];
//设置按钮的title的对齐方式
[cancelActionsetValue:[NSNumbernumberWithInteger:NSTextAlignmentLeft]forKey:@"titleTextAlignment"];
UIAlertAction*okAction = [UIAlertActionactionWithTitle:@"确认"style:UIAlertActionStyleDefaulthandler:nil];
[alertaddAction:okAction];
[alertaddAction:cancelAction];
[selfpresentViewController:alertanimated:YEScompletion:nil];