MFMailComposeViewController in iOS 7 statusbar are black

前端 未结 13 780
不知归路
不知归路 2020-12-04 23:20

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.

相关标签:
13条回答
  • 2020-12-04 23:58

    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];
    }];
    
    0 讨论(0)
  • 2020-12-04 23:58

    None of above answers are work for me.

    I have two issues.

    1. Black status bar
    2. transparent layer on title bar

    enter image description here

    Solution

    1. Black status - I remove all navigation bar customization

      // comment below line in AppDelegate

      [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forBarMetrics:UIBarMetricsDefault];

    2. Transparent title bar - set navigationBarHidden = Yes for MFMailComposeViewController

      composeViewController.navigationBarHidden = YES;

    0 讨论(0)
  • 2020-12-05 00:02

    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
        }
    }
    
    0 讨论(0)
  • 2020-12-05 00:02

    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.

    0 讨论(0)
  • 2020-12-05 00:06

    What did the trick for me was:

    • Subclass MFMailComposeViewController
    • 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];
      }

    0 讨论(0)
  • 2020-12-05 00:06

    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
            }
        }
    
    0 讨论(0)
提交回复
热议问题