19

iOS7 introduced general tint-color. I think UIAlertView is also in the valid range, but actually tintColor doesn't look to work with UIAlertView. (for tappable button text color)

Is it possible to change the tint-color of alert view? If possible, how to change it?

eonil
  • 83,476
  • 81
  • 317
  • 516
  • Try to see [PMAlertController](https://github.com/Codeido/PMAlertController) a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable alert. – Paolo Musolino Jul 03 '17 at 10:06

3 Answers3

26

Unfortunately you cannot customize the appearance of alert views, it is impossible to change the buttons text color.

It is mentioned clearly in 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.

Update:

The question was about iOS7, but now UIAlertView is deprecated, for UIAlertController you can simply change the view tint color:

    let alert = UIAlertController(title: "Gimme a break",
                                message: "For God sake its iOS7 question!",
                         preferredStyle: .alert)
    alert.view.tintColor = UIColor.red

It is helpful also to check this question: How to change UIAlertController button text colour in iOS9?

Community
  • 1
  • 1
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • 2
    @downvoter instead of this cowardly downvote, please tell us if we to achieve that using `UIAlertView`! – Tarek Hallak Mar 29 '14 at 09:13
  • -(void)willPresentAlertView:(UIAlertView *)alertView should give you an option to edit ALL subviews, and inevitably the cancel button is a subview of that 'alertview' object. couldn't find it though.. – eiran May 05 '14 at 14:09
  • 2
    You *shouldn't*. But you **can**. – wouterds May 13 '14 at 11:22
  • 1
    Just come across this and it is so correct so +1. As for the other two comments, @eiran just **NO** very very bad advise you **Shouldn't** mess with the view hierarchy of a `UIAlertView` this is perfectly clear in the documentation. Doing so is a one fast track ticket to getting your application rejected by Apple. as for `WouterDS` The only reason you can add subviews is because `UIAlertView` is a subclass of `UIView` which allows the view hierarchy to be messed with so whilst you can you **SHouldn't** – Popeye Jun 11 '14 at 09:58
  • 4
    This is possible: `[[UIView appearance] setTintColor:[UIColor redColor]];` However know that this tints all other tintable views too. – gdub Mar 17 '15 at 17:37
  • This is no longer true. Kevin Renella's answer works great for me: `[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertView class]]] setTintColor:[UIColor redColor]];` – Epaga Feb 08 '17 at 14:02
2

UIActionSheet can also change buttons' color by this way.

[[UIView appearance] setTintColor:[UIColor redColor]];
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
2

The previous answers mentioning [[UIView appearance] setTintColor:[UIColor redColor]]; should work but this code is doing way more than if should if you want to change only the UIAlertView tint color.

You can aim the 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
  • This is the same exact answer that you posted https://stackoverflow.com/a/36430459/4833705. You could have added a link to your previous question under the comments. Please don't post duplicate answers – Lance Samaria Jan 13 '22 at 15:42