cgeek
cgeek

Reputation: 588

ios 11 issue in MFMailComposeViewController's navigation bar

I used below code to present a MFMailViewController. Everything worked perfectly until ios 11 release.

                let mailViewController = MFMailComposeViewController()
                mailViewController.mailComposeDelegate = self               
                mailViewController.setToRecipients(nil)
                mailViewController.setSubject("Subject")
                mailViewController.navigationBar.tintColor = UIColor.green
                UINavigationBar.appearance().isTranslucent = false
                self.present(mailViewController, animated: true, completion:  nil)

No matter what code I use, nothing is working. I am able to present a controller , but navigation bar tint color is not changing. This issue is only with ios 11. I have set overall app navigation bar tint color to white. Hence in controller I get white tint color not green.

Upvotes: 1

Views: 1292

Answers (2)

cgeek
cgeek

Reputation: 588

I finally found what was wrong. I globally modified UIBarButton in one of the file.

UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.theme, NSFontAttributeName : UIFont.regularAppFontOfSize(0.0)], for: UIControlState.normal)

Even though I used mailViewController.navigationBar.tintColor = UIColor.green , because of global modification , it didn't have any effect.

But what's surprising is, there was no problem in ios 10 and below, but in ios 11.

If any one know the reason, its appreciated.

Upvotes: 3

LukeP
LukeP

Reputation: 11

I'm presenting this function and it's looking fine to me on iOS 11.

override func viewDidLoad() {
    super.viewDidLoad()

    self.present(self.configuredMailComposeViewController(), animated: true, completion: nil)
}

func configuredMailComposeViewController() -> MFMailComposeViewController {
    let mailComposeViewController = MFMailComposeViewController()
    mailComposeViewController.mailComposeDelegate = self
    mailComposeViewController.setSubject("Your subject and stuff like that")

    let nav = self.navigationController?.navigationBar
    nav?.barStyle = UIBarStyle.default
    nav?.tintColor = UIColor.green
    nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.green]

    return mailComposeViewController
}

Upvotes: 1

Related Questions