iOS UIActionController颜色字体修改

释放双眼,带上耳机,听听看~!
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
//修改title
NSString *title = @"UIAlertController 的简单属性";
NSMutableAttributedString *alertTitleStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",title]];
[alertTitleStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#333333"] range:NSMakeRange(0, alertTitleStr.length)];
[alertTitleStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, alertTitleStr.length)];
[alertC setValue:alertTitleStr forKey:@"attributedTitle"];
//修改message
NSMutableAttributedString *alertMessageStr = [[NSMutableAttributedString alloc] initWithString:@"n修改Message的简单属性"];
[alertMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#999999"] range:NSMakeRange(0, alertMessageStr.length)];
[alertMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, alertMessageStr.length)];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *OKBtn = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
/*设置行间距*/
[paragraph setLineSpacing:3];
/*设置段间距*/
[paragraph setParagraphSpacingBefore:5];
/*标题颜色*/
[alertVC setValue:alertMessageStr forKey:@"attributedMessage"];
/*内容颜色*/
[alertVC setValue:alertTitleStr forKey:@"attributedTitle"];
/*取消按钮的颜色*/
[cancel setValue:[UIColor colorWithHexString:@"#999999"] forKey:@"_titleTextColor"];
/*确认按钮的颜色*/
[OKBtn setValue:[UIColor colorWithHexString:@"#50D7ED"] forKey:@"_titleTextColor"];
[alertVC addAction:cancel];
[alertVC addAction:OKBtn];
[self presentViewController:alertVC animated:YES completion:nil];

慢慢来,一步一个巴掌印。。。。。

人已赞赏
iOS文章

iOS开发一个View根据设备尺寸的不同加载不同的XIB文件

2020-2-14 13:44:11

iOS文章

XCode 升级到 XCode10.3 项目报错 Failed to find or create execution context for description

2020-2-14 15:14:32

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索