//使用富文本来改变UIAlertController的title字体大小和颜色

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

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

推荐阅读更多精彩内容