Adam Bardon Adam Bardon - 6 months ago 110
Swift Question

MFMailComposeViewController navigationBar custom background color

I'm using MFMailComposeViewController and I'd like to change background color so it matches the one I have across the app. I've tried several things, but nothing worked(at least not on iOS 9).

let mailVC = MFMailComposeViewController()
mailVC.mailComposeDelegate = self
...

mailVC.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName: UIColor.whiteColor()] // this works
mailVC.navigationBar.tintColor = UIColor.whiteColor() // this works
mailVC.navigationBar.barTintColor = UIColor.blueColor() // this doesn't work
mailVC.navigationBar.backgroundColor = UIColor.blueColor() // this doesn't work


Background color stays default gray.

Answer

I solved it by setting color of navigationbar before initializing MFMailComposeViewController like this:

UINavigationBar.appearance().barTintColor = UIColor.blueColor()

let mailVC = MFMailComposeViewController()