Adrian Adrian - 3 months ago 15
Swift Question

Changing color of text on send/cancel buttons on MFMailComposeViewController

I'm putting the finishing touches on an app and testing on a physical device. Just as I tought I was crossing the finish line to submit to the App Store, I encountered an issue with the color a

MFMailComposeViewController's
send
and
cancel
buttons. I've dug through a lot of answers here, but none of them seem to get me over the finish line.

The methods below work to send e-mail, but regardless of what I do, the color of the send/cancel buttons remains the default blue color. Any suggestions to rectify this situation are greatly appreciated.

Thank you!

@IBAction func sendFeedbackEmail(sender: AnyObject) {
feedbackButton.pop()
print("sendFeedbackEmail called")
let mailComposeViewController = configuredMailComposeViewController()
// mailComposeViewController.navigationBar.translucent = false
// mailComposeViewController.navigationBar.barTintColor = UIColor.whiteColor()
// mailComposeViewController.navigationItem.rightBarButtonItem?.tintColor = UIColor.whiteColor()
// mailComposeViewController.navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
// UIBarButtonItem.appearance().tintColor = UIColor.whiteColor()

if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}

func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
// UIBarButtonItem.appearance().tintColor = UIColor.whiteColor()
// UINavigationBar.appearance().barTintColor = UIColor.whiteColor() // optional to change bar backgroundColor
mailComposerVC.navigationBar.translucent = false
mailComposerVC.navigationBar.barTintColor = UIColor.whiteColor()
mailComposerVC.setToRecipients(["frustratedDev@gmail.com"])
mailComposerVC.setSubject("Feedback")

return mailComposerVC
}

Answer

Here is the answer. I hope, you are not using baseViewController for UIViewController.

@IBAction func sendFeedbackEmail(sender: AnyObject) {
     feedbackButton.pop()
     print("sendFeedbackEmail called")
     let mailComposeViewController = configuredMailComposeViewController()

     if MFMailComposeViewController.canSendMail() {

       mailComposeViewController.navigationBar.tintColor = UIColor.redColor()

      self.presentViewController(mailComposeViewController, animated: true, completion: nil)

     } else {
         self.showSendMailErrorAlert()
     }
 }