How do I make the color of UIBarButtonItems for MFMailComposeViewController from the default blue?

女生的网名这么多〃 提交于 2020-01-03 16:58:49

问题


No matter what I seem to try, in the email screen that comes up when a user chooses to email a link (it's a MFMailComposeViewController) the buttons are always the default blue.

I have this in my 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] }];

And it does indeed color the title of the MFMailComposeViewController but not the buttons. How do I accomplish that?

It also keeps my status bar black when I have it white everywhere else.


回答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];
}];

Since iOS 6, MFMailComposeViewController (and some other view controllers) are run on a separate process, as such they will not inherit the style used in your app. Using the above method may help, it does, at least work on iOS 7, assuming you're using the most up-to-date SDK. You can read more about remote view controllers here.




回答2:


You can set a global tint color for your UIBarButtonItems in AppDelegate so that the MFMailComposeViewController will use it as color for its own buttons.

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


来源:https://stackoverflow.com/questions/19736481/how-do-i-make-the-color-of-uibarbuttonitems-for-mfmailcomposeviewcontroller-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!