i have a feedback button in my ios 7 application with MFMailComposeViewController. After the user click this button the mailcomposer open but the statusbar changed to black.
Some times it will not update the status bar style properly. You should use
[self setNeedsStatusBarAppearanceUpdate];
To say iOS to refresh the status bar style, manually. Hope someone would save some time on knowing it.
[self presentViewController:picker animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[self setNeedsStatusBarAppearanceUpdate];
}];
None of above answers are work for me.
I have two issues.
Solution
Black status - I remove all navigation bar customization
// comment below line in AppDelegate
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forBarMetrics:UIBarMetricsDefault];
Transparent title bar - set navigationBarHidden = Yes for MFMailComposeViewController
composeViewController.navigationBarHidden = YES;
Swift solution.
Set View controller-based status bar appearance
to YES
import UIKit
import MessageUI
import AddressBookUI
extension MFMailComposeViewController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func childViewControllerForStatusBarStyle() -> UIViewController? {
return nil
}
}
extension ABPeoplePickerNavigationController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func childViewControllerForStatusBarStyle() -> UIViewController? {
return nil
}
}
iOS 7 introduces a method prefersStatusBarHidden
, but it won't be so easy to use in this case. You may prefer to use the statusBarHidden
property of UIApplication
while the modal is presented.
What did the trick for me was:
Override the two methods as described in answer 6
-(UIStatusBarStyle)preferredStatusBarStyle;
-(UIViewController *)childViewControllerForStatusBarStyle;
Override viewDidLoad as follows:
-(void)viewDidLoad {
[super viewDidLoad];
[self preferredStatusBarStyle];
[self setNeedsStatusBarAppearanceUpdate];
}
It seems that initializing the MFMailComposeViewController UIApplication.shared.statusBarStyle will change to .default... so, saving the state before and setting it again after presentation solved the problem for me:
// save the state, otherwise it will be changed
let sbs = UIApplication.shared.statusBarStyle
let mailComposerVC = MailComposerVC()
mailComposerVC.navigationBar.barTintColor = UINavigationBar.appearance().barTintColor
mailComposerVC.navigationBar.tintColor = UINavigationBar.appearance().tintColor
mailComposerVC.navigationBar.barStyle = UINavigationBar.appearance().barStyle
if MFMailComposeViewController.canSendMail() {
APP_ROOT_VC?.present(mailComposerVC, animated: true, completion: {
// reapply the saved state
UIApplication.shared.statusBarStyle = sbs
})
}
public class MailComposerVC: MFMailComposeViewController {
public override var preferredStatusBarStyle: UIStatusBarStyle {
return UIApplication.shared.statusBarStyle
}
public override var childViewControllerForStatusBarStyle : UIViewController? {
return nil
}
}