Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change button title color in UIAlertView

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

enter image description here

I want title Ok in red color.

like image 934
Bandish Dave Avatar asked Jun 11 '14 08:06

Bandish Dave


3 Answers

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]];
like image 170
Kévin Renella Avatar answered Sep 28 '22 05:09

Kévin Renella


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

UIAlertController *alertController = ....
[alertController.view setTintColor:[UIColor greenColor]];
like image 11
Travis Weerts Avatar answered Oct 31 '22 15:10

Travis Weerts


for Swift 3, use:

alertController.view.tintColor = UIColor.red

AFTER you present your alert controller

like image 9
Dory Daniel Avatar answered Oct 31 '22 15:10

Dory Daniel