In iOS 8, it seems that buttons on UIAlertController
(specifically the action sheet type) as well as buttons on the UIActivityViewController
get their color from the main window's tintColor.
How can I change the color of the button text? I've tried using the appearance proxy like this:
[[UIButton appearanceWhenContainedIn:[UIActivityViewController class], nil] setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
But it has no effect. My window's tintColor is white, so the text on the UIActivityViewController buttons is also white, and it cannot be seen. Changing my window's tintColor resolves this issue, but it messes up the rest of the app.
See the screenshot of my UIActivityViewController
with a white cancel button with white text on the bottom:
The same thing applies to UIActionSheet (yes, I know it's deprecated) and UIAlertController with the actionSheet type.
How can I make the text on these windows readable without changing the tintColor of the entire app?? Thanks in advance!
In addition to the global tint color defined for your application, each view controller allows you to override the tint color for just that controller. In this case your best bet would be to set the tintColor on your UIActivityViewController after initializing but before presenting.
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:activities];
//Set the tint color on just the activity controller as needed here before presenting
[activityController.view setTintColor:[UIColor blueColor]];
[self presentViewController:activityController animated:YES completion:nil];
If you are doing this a lot in your app you could use a subclass or a category to avoid code duplication.