UIAlertController*alert = [UIAlertControlleralertControllerWithTitle:@"標(biāo)題"message:@"內(nèi)容"preferredStyle:UIAlertControllerStyleAlert];
//使用富文本來改變alert的title字體大小和顏色
NSMutableAttributedString*title = [[NSMutableAttributedStringalloc]initWithString:@"這里是標(biāo)題"];
[titleaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:24]range:NSMakeRange(0,2)];
[titleaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(0,2)];
[alertsetValue:titleforKey:@"attributedTitle"];
//使用富文本來改變alert的message字體大小和顏色
// NSMakeRange(0, 2)代表:從0位置開始兩個(gè)字符
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];
//設(shè)置按鈕背景圖片
UIImage*accessoryImage = [[UIImageimageNamed:@"3.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[cancelActionsetValue:accessoryImageforKey:@"image"];
//設(shè)置按鈕的title顏色
[cancelActionsetValue:[UIColorlightGrayColor]forKey:@"titleTextColor"];
//設(shè)置按鈕的title的對(duì)齊方式
[cancelActionsetValue:[NSNumbernumberWithInteger:NSTextAlignmentLeft]forKey:@"titleTextAlignment"];
UIAlertAction*okAction = [UIAlertActionactionWithTitle:@"確認(rèn)"style:UIAlertActionStyleDefaulthandler:nil];
[alertaddAction:okAction];
[alertaddAction:cancelAction];
[selfpresentViewController:alertanimated:YEScompletion:nil];