更改UIAlertView中的button标题颜色

如何更改UIAlertViewbutton标题的颜色。

在这里输入图像说明

我想要红色的标题Ok

实际上,你可以在iOS8中改变UIAlertController视图的色调。

 UIAlertController *alertController = .... [alertController.view setTintColor:[UIColor greenColor]]; 

对于Swift 3,请使用:

 alertController.view.tintColor = UIColor.red 

您出示警报控制器之后

您无法更改警报视图。 如果你真的需要你可以使用自定义的 。

无法自定义警报视图的外观。

欲了解更多信息UIAlertView类参考:

UIAlertView类旨在按原样使用,不支持子类。 这个类的视图层次是私有的,不能被修改。

更多信息: 如何在iOS7中更改UIAlertView的button文本颜色?

最好的方法(和最简单)是以下几点:

 alert = UIAlertController(title: "foo", message: "foo", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction.... foo ...foo alert.view.backgroundColor = UIColor.orangeColor() alert.view.tintColor = UIColor.orangeColor() alert.view.layer.cornerRadius = 0.5 * alert.view.bounds.size.width 

它也给背景中的“圆形淡橙色圆圈”的加上效果。

希望能帮助到你

如果您使用的是UIAlertController ,Travis Weerts答案应该可以工作。 对于那些使用UIAlertView ,您可以使用UIView外观设置。

您可以在iOS上以这种方式瞄准警报组件: <9

 [[UIView appearanceWhenContainedIn:[UIAlertView class], nil] setTintColor:[UIColor redColor]]; [[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]]; 

在iOS 9上

 [[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertView class]]] setTintColor:[UIColor redColor]]; [[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertController class]]] setTintColor:[UIColor redColor]]; 

尝试这个:

 [[UIView appearance] setTintColor:[UIColor whiteColor]];