Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 572
Adam Bardon Avatar asked May 27 '16 19:05

Adam Bardon


1 Answers

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

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

let mailVC = MFMailComposeViewController()
like image 177
Adam Bardon Avatar answered Sep 29 '22 12:09

Adam Bardon