AlertController的title、message和按钮颜色设置

//设置message

NSMutableAttributedString *messageStr = [[NSMutableAttributedString alloc] initWithString:@"message"];

[messageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];

[messageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 5)];

[alertController setValue:messageStr forKey:@"attributedMessage"];

[self presentViewController:alertController animated:YES completion:nil];

//设置title

NSMutableAttributedString *titleStr = [[NSMutableAttributedString alloc]initWithString:@"Title"];

[titleStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,2)];

[titleStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15]range:NSMakeRange(0,2)];

[alertController setValue:titleStr forKey:@"attributedTitle"];

//设置按钮颜色

UIAlertAction:

if (iOS9Later && [action.title isEqualToString:@"确定"] ) {

[action setValue:[UIColor greenColor] forKey:@"titleTextColor"];

} else {

[action setValue:[UIColor redColor] forKey:@"titleTextColor"];

}

你可能感兴趣的:(AlertController的title、message和按钮颜色设置)