从 iOS7 中的 UIActivityViewController 呈现时,无法在邮件编辑器中设置发送和取消按钮的文本颜色 [英] Cannot set text color of Send and Cancel buttons in the mail composer when presented from the UIActivityViewController in iOS7
问题描述
我正在使用 UIActivityViewController 在 iOS7 中共享项目.当我点击邮件选项时,它会弹出邮件编辑器,但是导航栏上的取消和发送按钮以及导航栏本身都是蓝色的,很难阅读,所以我想改变它们的颜色.它适用于 iOS6,但不适用于 iOS7.
I am using the UIActivityViewController to share items in iOS7. When I tap on the Mail option, it pops up the mail composer, but the Cancel and Send buttons on the navigation bar and the navigation bar itself are blue, making it very difficult to read, so I want to change their color. It's working in iOS6 but not in iOS7.
我试过了
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], UITextAttributeTextColor, [UIColor clearColor], UITextAttributeTextShadowColor, nil] forState:UIControlStateNormal];
适用于 iOS6,我试过了
which works in iOS6, and I tried
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
这会导致应用程序第一次运行时颜色闪烁红色,然后立即切换回蓝色.
which causes the color to flash red the first time the app is run before immediately switching back to the blue color.
推荐答案
管理更改发送和取消按钮的文本颜色,它们位于MFMailComposerViewController
(发送和取消)和MFMessageComposeViewController
(仅限取消),当从 UIActivityViewController
呈现时.
Managed to change the text color of the Send and Cancel buttons, which are on the UINavigationBar
in the MFMailComposerViewController
(both Send and Cancel) and MFMessageComposeViewController
(only Cancel), when presented from UIActivityViewController
.
使用 UIActivityViewController,点击 Message
或 Mail
:
Using an UIActivityViewController, tap on Message
or Mail
:
您会注意到发送和取消按钮的默认文本颜色为蓝色:
You'll notice that the default text color of the Send and Cancel buttons is blue:
为了改变这一点,在 AppDelegate.m
类的 didFinishLaunchingWithOptions
方法中,插入以下行:
In order to change that, in the AppDelegate.m
class, in the didFinishLaunchingWithOptions
method, insert the following line:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]];
这导致:
您也可以使用其他颜色,例如:
You can also use other colors, for example:
[UIColor PurpleColor];
[UIColor greenColor];
我是如何测试这个的?我注意到此解决方案适用于以下情况:
- 使用 Xcode 5.1,在 iOS 7.1 模拟器中,构建为基础 iOS SDK 7.1(可以从选择项目文件 -> 构建设置 -> 基础 SDK 中选择.另外,从常规 -> 部署目标 -> 7.1 中选择)
- 使用 Xcode 5.1,在 iPhone 4 上构建为基础 iOS SDK 7.0(可以从选择项目文件 -> 构建设置 -> 基础 SDK 中进行选择.此外,从常规 -> 部署目标 -> 7.0 中选择)
- 使用 Xcode 5.1,在 iPhone 4 上构建为基础 iOS SDK 7.1(可以从选择项目文件 -> 构建设置 -> 基础 SDK 中进行选择.此外,从常规 -> 部署目标 -> 7.1 中选择)
测试时不起作用:
- 使用 Xcode 5.1,在 iOS 7.0 模拟器中,构建为 base iOS SDK 7.0(可以从选择项目文件 -> Build Settings -> Base SDK 中选择.另外,从 General -> Deployment Target -> 7.0 中选择)
因此使用起来应该是安全的,因为我相信实际设备上的行为比 iOS 模拟器中的行为更重要.如果有人知道为什么它在 iOS 7.0 模拟器中不起作用,我想知道.:)
Therefore it should be safe to use, as I believe the behavior on the actual device matters more than the behavior in the iOS simulator. If anyone knows why it doesn't work in the iOS 7.0 simulator, I would like to know. :)
这篇关于从 iOS7 中的 UIActivityViewController 呈现时,无法在邮件编辑器中设置发送和取消按钮的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!