如何从默认的蓝色为MFMailComposeViewController生成UIBarButtonItems的颜色?

时间:2013-11-01 22:33:37

标签: ios objective-c ios7 mfmailcomposeviewcontroller uiappearance

无论我多么尝试,在用户选择通过电子邮件发送链接时出现的电子邮件屏幕(它是MFMailComposeViewController),按钮始终是默认的蓝色。

我在AppDelegate中有这个:

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.000 green:156/255.0 blue:51/255.0 alpha:1]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName: [UIColor whiteColor] }];

它确实为MFMailComposeViewController但不是按钮的标题着色。我该如何做到这一点?

当我在其他地方将白色显示为白色时,它也会使我的状态栏保持黑色。

2 个答案:

答案 0 :(得分:16)

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setToRecipients: [NSArray arrayWithObjects:@"recipients", nil]];
[mailController setSubject: @"Contact Us"];
[mailController setMessageBody: @"Mail Body" isHTML:NO];
[[mailController navigationBar] setTintColor: [UIColor blackColor]]; //color
[self presentViewController: mailController animated:YES completion:^{
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
}];

由于iOS 6,MFMailComposeViewController(以及其他一些视图控制器)在单独的进程上运行,因此它们不会继承应用程序中使用的样式。假设您正在使用最新的SDK,使用上述方法可能会有所帮助,至少可以在iOS 7上运行。 You can read more about remote view controllers here.

答案 1 :(得分:0)

您可以在AppDelegate中为UIBarButtonItem设置全局色调颜色,以便MFMailComposeViewController将其用作自己按钮的颜色。

    let barButtonItemAppearance = UIBarButtonItem.appearance()
    barButtonItemAppearance.tintColor = KK.GRAPHICS.COLOR_WHITE