【问题标题】:How do I make the color of UIBarButtonItems for MFMailComposeViewController from the default blue?如何使 MFMailComposeViewController 的 UIBarButtonItems 的颜色从默认的蓝色?
【发布时间】:2013-11-01 22:33:36
【问题描述】:

无论我尝试什么,当用户选择通过电子邮件发送链接(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 的标题着色,但不是按钮。我该如何做到这一点?

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

【问题讨论】:

标签: ios objective-c ios7 mfmailcomposeviewcontroller uiappearance


【解决方案1】:
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.

【讨论】:

  • 嗯,知道为什么状态栏仍然保持黑色吗?您的解决方案非常适合 UIBarButtonItems。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    相关资源
    最近更新 更多