通过runtime获取对应的可以修改的key来修改UIAlertController的系统样式,标题、内容的字体大小,颜色等及按钮的颜色
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确认离开支付?" message:@"你的订单在30分钟内未支付将被取消,请尽快支付" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"继续支付" style:UIAlertActionStyleDestructive handler:nil];
UIAlertAction *quiteAction = [UIAlertAction actionWithTitle:@"确定离开" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popToRootViewControllerAnimated:YES];
}];
/*title*/
NSMutableAttributedString *alertTitleStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];
[alertTitleStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, alertTitleStr.length)];
[alertTitleStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, alertTitleStr.length)];
[alertController setValue:alertTitleStr forKey:@"attributedTitle"];
/*msg*/
NSMutableAttributedString *alertMsgStr = [[NSMutableAttributedString alloc] initWithString:@"修改内容"];
[alertTitleStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, alertMsgStr.length)];
[alertTitleStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, alertMsgStr.length)];
[alertController setValue:alertMsgStr forKey:@"attributedMessage"];
[quiteAction setValue:PMTitleColor forKey:@"_titleTextColor"];
[cancleAction setValue:[UIColor colorWithHexValue:0x3FBE8C alpha:1.0f] forKey:@"_titleTextColor"];
[alertController addAction:cancleAction];
[alertController addAction:quiteAction];
[self presentViewController:alertController animated:YES completion:nil];