I'm currently having some difficulty trying to set the Cancel and Send button colors when I navigate to MFMailComposeViewController in iOS 10 using swift 3. I've tried setting the tint of the MFMailComposeViewController's UINavigationController, Bar, and Items with no success. Any help would be much appreciated.
How I open MFMailComposeViewController:
/* Open mail for the user to send a help emaail with questions about the app */
func sendEmail() {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["[email protected]"])
mail.navigationBar.tintColor = UIColor.blue
present(mail, animated: true)
}
}
/* Called when mail is dismissed */
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
If you want a navigation color for your entire app, i.e the tints of the buttons match throughout the app you can try this:
Inside the func application(_ application: UIApplication, didFinishLaunchingWithOptions
of AppDelegate
// Custom color for navigation bar
UINavigationBar.appearance().tintColor = UIColor.whateverTintColorYouWant
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whateverTextColorYouWant]
If you would only like this for the MailViewController try this:
// Custom color for navigation bar
mail.navigationController?.navigationBar.tintColor = UIColor.aColorYouwant
mail.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.aColorYouWant]
The final answer for me was the first comment from here: How to change color of MFMailComposeViewController texts and button images? Where you have to set
mail.view.tintColor = .green
Then my buttons appeared green.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With