Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Navigation Bar Item Colors in MFMailComposeViewController

Tags:

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.

What my current MFMailComposeViewController looks like

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)
    }
like image 961
user3459799 Avatar asked Nov 03 '16 18:11

user3459799


2 Answers

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]
like image 177
Luis Avatar answered Sep 25 '22 16:09

Luis


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.

like image 30
FrugalResolution Avatar answered Sep 25 '22 16:09

FrugalResolution