iOS 8 UIActivityViewController和UIAlertController按钮文本颜色使用窗口的tintColor [英] iOS 8 UIActivityViewController and UIAlertController button text color uses window's tintColor

查看:100
本文介绍了iOS 8 UIActivityViewController和UIAlertController按钮文本颜色使用窗口的tintColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 8中,似乎 UIAlertController 上的按钮(特别是操作表类型)以及 UIActivityViewController 从主窗口的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];

但它没有效果。我的窗口的tintColor是白色的,因此UIActivityViewController按钮上的文本也是白色的,无法看到。更改我的窗口的tintColor解决了这个问题,但它弄乱了应用程序的其余部分。

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.

查看我的 UIActivityViewController 的屏幕截图,底部带有白色文字的白色取消按钮:

See the screenshot of my UIActivityViewController with a white cancel button with white text on the bottom:

同样的事情适用于UIActionSheet(是的,我知道它已被弃用)和带有actionSheet类型的UIAlertController。

The same thing applies to UIActionSheet (yes, I know it's deprecated) and UIAlertController with the actionSheet type.

如何制作文本在这些窗口可读而不改变整个应用程序的tintColor ??在此先感谢!

How can I make the text on these windows readable without changing the tintColor of the entire app?? Thanks in advance!

推荐答案

除了为应用程序定义的全局色调颜色外,每个视图控制器都允许您覆盖色调只有那个控制器的颜色。在这种情况下,你最好的选择是在初始化之后但在呈现之前在你的UIActivityViewController上设置tintColor。

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.

这篇关于iOS 8 UIActivityViewController和UIAlertController按钮文本颜色使用窗口的tintColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆