Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change tint color of UIAlertview and UIActionsheet buttons

I am trying to adapt my application for iOS 7. The issue I am having is I can not change the tint color of some controls.

I did add

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if (IOS7_OR_LATER)
    self.window.tintColor = [self greenTintColor];

to my app delegate's

           - (BOOL)application:(UIApplication *)application
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

It mostly helped but color of message box and action sheet buttons is still the default blue.

How can I recolor all such buttons too?

Some screenshots:

iOS7 message boxiOS7 action sheet

like image 958
Bobrovsky Avatar asked Nov 15 '13 06:11

Bobrovsky


3 Answers

Combining best answers above, and updated for deprecation:

[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertController class]]] setTintColor:[UIColor greenColor]];

or Swift:

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .green

Works in 2018, Swift 4 / iOS 12.

like image 164
jab Avatar answered Sep 17 '22 06:09

jab


I was able to change the cancel button's text color to white in app delegate.

[[UIView appearance] setTintColor:[UIColor whiteColor]];
like image 12
Ali Avatar answered Oct 24 '22 04:10

Ali


As UIAlertView is deprecated You can. Use UIAlertController.

You can use tintColor property.

OLD

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.

-From Apple Doc

You can use tintColor property or You can use Some Custom Library for that, you can find it at cocoacontrols.com.

like image 11
Toseef Khilji Avatar answered Oct 24 '22 04:10

Toseef Khilji