0

I am using iOS 14 device and whenever I open Mail View Composer, the 'Cancel' button on top left corner always shows up in white. I was able to set the color of send button, but not able to change the color for 'Cancel' button.

    let mailComposerVC = MFMailComposeViewController()
    mailComposerVC.mailComposeDelegate = self
    mailComposerVC.setToRecipients(toRecipientEmailIds)
    mailComposerVC.setSubject(subject)
    mailComposerVC.setMessageBody(messageBody, isHTML: false)

    if let topVC = UIApplication.shared.topMostViewController() {
        mailComposerVC.navigationBar.tintColor = UIColor(rgb: 0x057AFF)
        //mailComposerVC.navigationBar.isTranslucent = false
        //mailComposerVC.navigationBar.isOpaque = false
        UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = UIColor.white
        topVC.present(mailComposerVC, animated: true)
    }

How do I change text color for 'Cancel' button?

Thanks!

tech_human
  • 6,592
  • 16
  • 65
  • 107

2 Answers2

0

Remove the below as it probably is what is causing your cancel button to be white

UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = UIColor.white

You only need this

// set any color you want
mailComposerVC.navigationBar.tintColor = .green

MFMailComposerView cancel button navigation bar button tint swift iOS

Shawn Frank
  • 4,381
  • 2
  • 19
  • 29
  • What iOS version are you using? Sorry I mentioned iOS 14 in the description, my device is set to iOS 15 but while googling somewhere I read the issue is on iOS14+. I removed the line you pointed, but I am still seeing cancel button text in white. – tech_human Mar 21 '22 at 03:44
  • 1
    @tech_human I am actually using an iOS 14.4 device so this is probably an iOS 15 issue then. Have a look at some of these then for iOS 15 https://stackoverflow.com/questions/28733936/change-color-of-back-button-in-navigation-bar or https://stackoverflow.com/a/58377778/1619193 or https://stackoverflow.com/questions/69111478/ios-15-navigation-bar-transparent – Shawn Frank Mar 21 '22 at 04:19
  • Thanks for sharing the links! I will give look at it and give it a try. – tech_human Mar 21 '22 at 16:30
0

Maybe your AppDelegate.swift has set the value for all the NavigateBar

UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .normal)

Just remove above line, you will be able to set your mail cancel button color.

Please refer to this post: Cancel and send button missing on MFMailComposeViewController iOS

timyau
  • 812
  • 1
  • 16
  • 27