Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
763 views
in Technique[技术] by (71.8m points)

objective c - iOS 8 UIActivityViewController and UIAlertController button text color uses window's tintColor

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:

UIActivityViewController with white Cancel button text

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...