UIActionController颜色字体修改

2017-11-02  本文已影响10人  iLeooooo
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];

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

上一篇下一篇

猜你喜欢

热点阅读