MFMailComposeViewController in iOS 7 statusbar are black

前端 未结 13 778
不知归路
不知归路 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:46

    Try to add category to MFMailComposeViewController

    EDIT: this solution works if "View controller-based status bar appearance" == YES

    @implementation MFMailComposeViewController (IOS7_StatusBarStyle)
    
    -(UIStatusBarStyle)preferredStatusBarStyle
    {
       return UIStatusBarStyleLightContent;
    }
    
    -(UIViewController *)childViewControllerForStatusBarStyle
    {
       return nil;
    }
    
    @end
    
    0 讨论(0)
  • 2020-12-04 23:48

    I am building an application in iOS8 and have had issues with the status bar with all native functions such as the mail composer, the camera, etc.. The following will solve your issues:

    Put the following in your plist file

      <key>UIStatusBarHidden</key>
      <false/>
      <key>UIViewControllerBasedStatusBarAppearance</key>
      <false/>
    

    If you are using the add row feature in storyboard, the UIViewControllerBasedStatusBarAppearance is not an option. Also when adding a row it asks for BOOLEAN (YES/NO). It cannot be a NO string in the source code it must be a false boolean. Open the plist as source code instead and add the above rows. Remove your old attempts. You will now be able to successfully apply the code snippets given in so many incomplete answers found on the net.

    You can now add global changes in the app delegate file and/or overrides in the controllers themselves. Without the above being in place all the stack overflow code I have tried has failed when using a native function. Now all is working perfectly.

    As a test, replace any calls to any onboard "completion" calls with

        completion:^{[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];}
    
    0 讨论(0)
  • 2020-12-04 23:49
    [self presentViewController:mailViewController animated:YES completion:^(void) { [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; }];
    
    0 讨论(0)
  • 2020-12-04 23:51

    Solution for Swift3

    Add this to your ViewController:

    extension MFMailComposeViewController {
        open override var preferredStatusBarStyle: UIStatusBarStyle {
            return .lightContent
        }
        open override var childViewControllerForStatusBarStyle: UIViewController? {
            return nil
        }
    }
    

    Set View controller-based status bar appearance >> YES as below:

    Thanks to @SoftDesigner

    Another cleaner solution that may not change other settings in your app. While presenting the Mail VC change the status bar in the completion block:

    controller.present(mailComposeViewController, animated: true) {
                UIApplication.shared.statusBarStyle = .lightContent
            }
    
    0 讨论(0)
  • 2020-12-04 23:51

    The easiest swift 3 solution for me was:

    extension MFMailComposeViewController {
    
        open override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
    
            UIApplication.shared.statusBarStyle = .lightContent
        }
    }
    
    0 讨论(0)
  • 2020-12-04 23:58

    Set the UIApplication statusBarStyle in the completion block of presentViewController for your MFMailComposeViewController. i.e.

        MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
        [self.navigationController presentViewController:mailVC animated:YES completion:^{
            [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        }];
    

    You may also need to add and/or set "View controller-based status bar appearance" to NO in your Info.plist file.

    0 讨论(0)
提交回复
热议问题