3

I currently use the iOS 7 mechanism of defining the (UIStatusBarStyle)preferredStatusBarStyle selector on UINavigationController subclasses to control the appearance of the status bar in modally presented views (returning UIStatusBarStyleLightContent). With an instance of MFMailComposeViewController, I am unable to affect the appearance of the status bar in any way.

It seems like the issue is that the top view of the MFMailComposeViewController (which is a UINavigationController subclass) is a MFMailComposeInternalViewController, which is private and undocumented and seems like something I shouldn't be messing with. Trying to subclass or create a category of it generates compiler errors. It's preferredStatusBarStyle is UIStatusBarStyleDefault, where I want it to be UIStatusBarStyleLightContent.

Other answers have suggested setting the plist value of "View controller-based status bar appearance" to NO, but I cannot do this without affecting other portions of my application. Is there any way to change the appearance of this status bar?

Regan
  • 1,487
  • 2
  • 28
  • 43
  • I don't think that you are allowed to mess with the MFMailComposerViewController or the MessageComposerViewController because they are Apple's copyright, or "property" I should say. – user2277872 Sep 19 '13 at 00:02
  • I have the same issue. Ever find a workaround? – Stephen Sep 25 '13 at 02:37

2 Answers2

2

MFMailComposeViewController, since iOS6, is not actually a real view controller, or rather, it does not hold the true view hierarchy of the mail composition view controller. Instead, it is a proxy for a remote view controller, drawn by a different process entirely, using XPC.

Even if you override or swizzle methods in the MFMailComposeViewController class, you will not be able to affect its behavior. This is on purpose by Apple.

More information on remote view controllers and XPC here: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
1

Adding a category to MFMailComposeViewController (instead of MFMailComposeInternalViewController) to provide the preferredStatusBarStyle worked for me and didn't generate any compile errors or warnings.

See this question for the original answer I referenced:

MFMailComposeViewController in iOS 7 statusbar are black

Community
  • 1
  • 1
lintmachine
  • 245
  • 1
  • 11
  • Did you also enable UIViewControllerBasedStatusBarAppearance? That is a prerequisite for this to work. – lintmachine Oct 01 '13 at 16:17
  • If I enable this param status bar font color becomes black for all controllers in my app. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; stops to work. - (UIStatusBarStyle)preferredStatusBarStyle {     return UIStatusBarStyleLightContent; } also doesn't help. – Yarlik Oct 02 '13 at 11:34
  • 1
    This isn't a reliable solution, because categories shouldn't be used to override existing methods: https://stackoverflow.com/a/5272612/18278 – erikprice Oct 07 '17 at 13:20
  • Is it legal to subclass `MFMailComposeViewController`? – igrek Nov 14 '17 at 15:16