Change button title color in UIAlertView

扶醉桌前 提交于 2019-12-01 03:33:16

Actually, you can change the tint color of the view of the UIAlertController in iOS8.

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

for Swift 3, use:

alertController.view.tintColor = UIColor.red

AFTER you present your alert controller

The Travis Weerts answer should work if you are using a UIAlertController. For those using UIAlertView, you can use the UIView appearance settings.

You can aim the alerts component this way on iOS < 9 :

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

And on iOS 9 :

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

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

Kumar KL

Can't customize the appearance of alert views.

For more info UIAlertView Class Reference:

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.

For more info : How to change button text color of UIAlertView in iOS7?

try this:

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

You can't change alert views. If you really needed you can use custom ones.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!