12

How can I change the color of the UIAlertView button title.

enter image description here

I want title Ok in red color.

Binarian
  • 12,296
  • 8
  • 53
  • 84
Bandish Dave
  • 791
  • 1
  • 7
  • 27
  • Just a quick question is this iOS7 or iOS8? I'm not sure how they look in iOS8 but `UIAlertView`s have been replaced with `UIAlertController` – Popeye Jun 11 '14 at 09:31
  • 2
    possible duplicate of [How to change button text color of UIAlertView in iOS7?](http://stackoverflow.com/questions/19193367/how-to-change-button-text-color-of-uialertview-in-ios7) – Stonz2 Jun 11 '14 at 14:28

7 Answers7

11

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

UIAlertController *alertController = ....
[alertController.view setTintColor:[UIColor greenColor]];
Travis Weerts
  • 152
  • 1
  • 5
9

for Swift 3, use:

alertController.view.tintColor = UIColor.red

AFTER you present your alert controller

Dory Daniel
  • 798
  • 14
  • 21
6

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]];
Kévin Renella
  • 1,007
  • 9
  • 20
3

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

1

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?

Community
  • 1
  • 1
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
  • 2
    copyed answer from http://stackoverflow.com/questions/19193367/how-to-change-button-text-color-of-uialertview-in-ios7 – Nitin Gohel Jun 11 '14 at 08:21
  • 3
    @NitinGohel Whilst they look simpler I don't think it could have been put any other way since this is basically from the Apple documentation. – Popeye Jun 11 '14 at 09:29
  • 2
    but true is that that is copied from i pasted link. – Nitin Gohel Jun 11 '14 at 09:33
  • 3
    @NitinGohel I suppose but I really don't think it could have been put any other way, that one sentence does cover the whole thing and is definitely a correct answer, so I don't think it should just be a comment. I suppose it would been better if the user referenced it from that link you have provided. – Popeye Jun 11 '14 at 09:53
0

try this:

[[UIView appearance] setTintColor:[UIColor whiteColor]];
Tea
  • 306
  • 4
  • 8
-1

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

mvadim
  • 152
  • 6