How can I change the color of the UIAlertView
button title.
如何更改UIAlertView按钮标题的颜色。
I want title Ok
in red color.
我希望红色的标题好。
7 个解决方案
#1
9
Actually, you can change the tint color of the view of the UIAlertController in iOS8.
实际上,您可以在iOS8中更改UIAlertController视图的色调颜色。
UIAlertController *alertController = ....
[alertController.view setTintColor:[UIColor greenColor]];
#2
4
for Swift 3, use:
对于Swift 3,使用:
alertController.view.tintColor = UIColor.red
AFTER you present your alert controller
在您出示警报控制器之后
#3
3
The Travis Weerts answer should work if you are using a UIAlertController
. For those using UIAlertView
, you can use the UIView
appearance settings.
如果您使用的是UIAlertController,Travis Weerts的答案应该有效。对于使用UIAlertView的用户,可以使用UIView外观设置。
You can aim the alerts component this way on iOS < 9 :
您可以在iOS <9上以这种方式瞄准警报组件:
[[UIView appearanceWhenContainedIn:[UIAlertView class], nil] setTintColor:[UIColor redColor]];
[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]];
And on iOS 9 :
在iOS 9上:
[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertView class]]] setTintColor:[UIColor redColor]];
[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertController class]]] setTintColor:[UIColor redColor]];
#4
2
The best way (And easiest) is the following:
最好的方法(也是最简单的)如下:
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
It gives also a plus effect of a "round faded orange circle" in the background.
它还在背景中给出了“圆形褪色橙色圆圈”的加号效果。
Hope it helps
希望能帮助到你
#5
1
Can't customize the appearance of alert views.
无法自定义警报视图的外观。
For more info UIAlertView Class Reference:
有关更多信息,请参阅UIAlertView类参考:
The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
UIAlertView类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。
For more info : How to change button text color of UIAlertView in iOS7?
有关更多信息:如何在iOS7中更改UIAlertView的按钮文本颜色?
#6
0
You can't change alert views. If you really needed you can use custom ones.
您无法更改警报视图。如果你真的需要,你可以使用自定义的。
#7
0
try this:
[[UIView appearance] setTintColor:[UIColor whiteColor]];
#1
9
Actually, you can change the tint color of the view of the UIAlertController in iOS8.
实际上,您可以在iOS8中更改UIAlertController视图的色调颜色。
UIAlertController *alertController = ....
[alertController.view setTintColor:[UIColor greenColor]];
#2
4
for Swift 3, use:
对于Swift 3,使用:
alertController.view.tintColor = UIColor.red
AFTER you present your alert controller
在您出示警报控制器之后
#3
3
The Travis Weerts answer should work if you are using a UIAlertController
. For those using UIAlertView
, you can use the UIView
appearance settings.
如果您使用的是UIAlertController,Travis Weerts的答案应该有效。对于使用UIAlertView的用户,可以使用UIView外观设置。
You can aim the alerts component this way on iOS < 9 :
您可以在iOS <9上以这种方式瞄准警报组件:
[[UIView appearanceWhenContainedIn:[UIAlertView class], nil] setTintColor:[UIColor redColor]];
[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]];
And on iOS 9 :
在iOS 9上:
[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertView class]]] setTintColor:[UIColor redColor]];
[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertController class]]] setTintColor:[UIColor redColor]];
#4
2
The best way (And easiest) is the following:
最好的方法(也是最简单的)如下:
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
It gives also a plus effect of a "round faded orange circle" in the background.
它还在背景中给出了“圆形褪色橙色圆圈”的加号效果。
Hope it helps
希望能帮助到你
#5
1
Can't customize the appearance of alert views.
无法自定义警报视图的外观。
For more info UIAlertView Class Reference:
有关更多信息,请参阅UIAlertView类参考:
The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
UIAlertView类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。
For more info : How to change button text color of UIAlertView in iOS7?
有关更多信息:如何在iOS7中更改UIAlertView的按钮文本颜色?
#6
0
You can't change alert views. If you really needed you can use custom ones.
您无法更改警报视图。如果你真的需要,你可以使用自定义的。
#7
0
try this:
[[UIView appearance] setTintColor:[UIColor whiteColor]];