在MFMailComposeViewController上更改发送/取消按钮上的文本颜色

时间:2016-08-05 14:46:19

标签: ios swift uinavigationbar mfmailcomposeviewcontroller

我正在对应用程序进行最后润色并在物理设备上进行测试。正如我所说的那样,我越过终点线提交到App Store,我遇到了MFMailComposeViewController's sendcancel按钮的颜色问题。我在这里挖掘了很多答案,但似乎没有一个能让我超越终点线。

以下方法可用于发送电子邮件,但无论我做什么,发送/取消按钮的颜色仍为默认蓝色。任何纠正这种情况的建议都非常感谢。

谢谢!

    @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
    }

3 个答案:

答案 0 :(得分:6)

Swift 4.0

mailComposeViewController.navigationBar.tintColor = UIColor.red

答案 1 :(得分:4)

这是答案。我希望你没有在UIViewController上使用baseViewController。

@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()
     }
 }

答案 2 :(得分:0)

在带有发送按钮 V 形的新 UI 样式的 swift 4+ 中,您只需要在 modalPresentationStyle = .fullscreen 中显示 composerVC。然后它也会改变发送按钮的颜色。希望这会有所帮助。

let mailComposeVC = MFMailComposeViewController()
mailComposeVC.mailComposeDelegate = self
mailComposeVC.modalPresentationStyle = .fullScreen
mailComposeVC.navigationBar.tintColor = UIColor(red:131/255.0, green:184/255.0, blue:26/255.0, alpha:1)
self.present(mailComposeVC, animated: true, completion: nil)

我搜索了几个小时,一无所获。我只是随机尝试并得到了解决方案。我希望这可以帮助任何搜索此问题的人。

enter image description here