swift – 在MFMailComposeViewController中设置导航栏项目颜色

当我使用
swift 3导航到iOS 10中的MFMailComposeViewController时,我正在尝试设置取消和发送按钮颜色时遇到一些困难.我尝试设置MFMailComposeViewController的UINavigationController,Bar和Items的色调没有成功.任何帮助将非常感激.

《swift – 在MFMailComposeViewController中设置导航栏项目颜色》

我如何打开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(["himom@gmail.com"])
            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)
    }

最佳答案 如果您想要整个应用程序的导航颜色,即按钮的色调在整个应用程序中匹配,您可以尝试这样做:

在func应用程序内部(_ application:UIApplication,AppDelegate的didFinishLaunchingWithOptions)

// Custom color for navigation bar
UINavigationBar.appearance().tintColor = UIColor.whateverTintColorYouWant
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whateverTextColorYouWant]

如果你只想为MailViewController这样做,试试这个:

// Custom color for navigation bar
mail.navigationController?.navigationBar.tintColor = UIColor.aColorYouwant
mail.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.aColorYouWant]
点赞