// ------------title ---------
NSMutableAttributedString *attTitleString = [[NSMutableAttributedString alloc] initWithString:titleString];
[_alertController setValue:attTitleString forKey:@"attributedTitle"];
// -----------message --------
NSMutableAttributedString *attMsgString = [[NSMutableAttributedString alloc] initWithString:messageString];
// 设置字体
[attMsgString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, attMsgString.length)];
// 设置颜色
[attMsgString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 10)];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
// 设置行间距
[paragraph setLineSpacing:3];
// 设置段间距
[paragraph setParagraphSpacingBefore:5];
// 设置对齐方式
[paragraph setAlignment:NSTextAlignmentLeft];
// 设置书写方向
[paragraph setBaseWritingDirection:NSWritingDirectionLeftToRight];
[attMsgString addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, attMsgString.length)];
[_alertController setValue:attMsgString forKey:@"attributedMessage"];
// ----按钮颜色------
NSArray *actionArr = [_alertController actions];
[actionArr.firstObject setTitle:alertTitle];
[actionArr.firstObject setValue:[UIColor orangeColor] forKey:@"titleTextColor"];
iOS开发 UIAlertController的 title、message、button的属性更改
最新推荐文章于 2025-06-24 10:16:52 发布
本文介绍如何使用Swift自定义UIAlertController的标题、消息文本及按钮样式,包括设置字体、颜色、行间距、段间距和对齐方式等,实现美观且功能丰富的警告视图。
401

被折叠的 条评论
为什么被折叠?



