简体   繁体   English

MFMailComposeViewController的导航栏中的ios 11问题

[英]ios 11 issue in MFMailComposeViewController's navigation bar

I used below code to present a MFMailViewController. 我使用下面的代码来呈现MFMailViewController。 Everything worked perfectly until ios 11 release. 在ios 11发行之前,一切工作正常。

                let mailViewController = MFMailComposeViewController()
                mailViewController.mailComposeDelegate = self               
                mailViewController.setToRecipients(nil)
                mailViewController.setSubject("Subject")
                mailViewController.navigationBar.tintColor = UIColor.green
                UINavigationBar.appearance().isTranslucent = false
                self.present(mailViewController, animated: true, completion:  nil)

No matter what code I use, nothing is working. 无论我使用什么代码,都无法正常工作。 I am able to present a controller , but navigation bar tint color is not changing. 我可以显示一个控制器,但导航栏的颜色不会改变。 This issue is only with ios 11. I have set overall app navigation bar tint color to white. 仅iOS 11才有此问题。我已将整个应用程序导航栏的颜色设置为白色。 Hence in controller I get white tint color not green. 因此,在控制器中,我得到的是白色而不是绿色。

I finally found what was wrong. 我终于找到了问题所在。 I globally modified UIBarButton in one of the file. 我在其中一个文件中全局修改了UIBarButton。

UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.theme, NSFontAttributeName : UIFont.regularAppFontOfSize(0.0)], for: UIControlState.normal)

Even though I used mailViewController.navigationBar.tintColor = UIColor.green , because of global modification , it didn't have any effect. 即使我使用了mailViewController.navigationBar.tintColor = UIColor.green ,由于进行了全局修改,它也没有任何作用。

But what's surprising is, there was no problem in ios 10 and below, but in ios 11. 但是令人惊讶的是,在ios 10及更低版本中没有问题,但是在ios 11中没有问题。

If any one know the reason, its appreciated. 如果有人知道原因,则表示赞赏。

I'm presenting this function and it's looking fine to me on iOS 11. 我正在介绍此功能,并且在iOS 11上看起来还不错。

override func viewDidLoad() {
    super.viewDidLoad()

    self.present(self.configuredMailComposeViewController(), animated: true, completion: nil)
}

func configuredMailComposeViewController() -> MFMailComposeViewController {
    let mailComposeViewController = MFMailComposeViewController()
    mailComposeViewController.mailComposeDelegate = self
    mailComposeViewController.setSubject("Your subject and stuff like that")

    let nav = self.navigationController?.navigationBar
    nav?.barStyle = UIBarStyle.default
    nav?.tintColor = UIColor.green
    nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.green]

    return mailComposeViewController
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM