How to change status bar to White in MFMailComposeViewController?

743 Views Asked by At

Pic is shown down below.

In my app, a have added an Email Prompt, but the status bar is black now, how can I change it to white style?

if MFMailComposeViewController.canSendMail() {
            let composeMail = MFMailComposeViewController()
            composeMail.mailComposeDelegate = self
            //  configs
            composeMail.setToRecipients(["[email protected]"])
            composeMail.setSubject("【饥荒口袋】反馈")
            composeMail.setMessageBody("问题页面:\n\n\n\n建议:\n", isHTML: false)
            composeMail.navigationBar.tintColor = UIColor.white.withAlphaComponent(0.85) // Mail VC's Button Color
            // TODO: - Change status bar color
            //  show it
            self.present(composeMail, animated: true, completion: nil)
}

Balck Status Bar - NOW

3

There are 3 best solutions below

1
On BEST ANSWER

Try to set statusBarStyle in completion handler while present mail controller like this

self.present(composeMail, animated: true, completion:{ () in
     UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
})

Hope it will work.

2
On

In viewWillAppear:

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
self.navigationController.navigationBar.translucent = false
self.navigationController.navigationBar.opaque = false
self.navigationController.navigationBar.barTintColor = UIColor.blueColor()}

To change the status bar color of the whole application write this line of code in app delegate

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

into your app delegates didFinishLoading.

0
On

Call this method before you present mail composer,

func setStatusBarBackgroundColor(color: UIColor) {

        guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }

        statusBar.backgroundColor = color
    }