【问题标题】:Set Navigation Bar Item Colors in MFMailComposeViewController在 MFMailComposeViewController 中设置导航栏项颜色
【发布时间】:2016-11-03 18:44:19
【问题描述】:

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

我如何打开 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)
    }

【问题讨论】:

  • 尝试设置撰写控制器视图本身的色调。
  • @LeoNatan 尝试在邮件对象初始化之前添加self.navigationController?.navigationBar.tintColor = UIColor.blue,但没有帮助。
  • 没有。试试mail.view.tintColor = .blue
  • 也没有运气。

标签: swift uinavigationcontroller uinavigationbar swift3


【解决方案1】:

如果您想要整个应用的导航颜色,即按钮的颜色在整个应用中匹配,您可以试试这个:

在AppDelegate 的func application(_ application: UIApplication, 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]

【讨论】:

  • 我可以从 AppDelegate 设置背景和标题颜色。我无法设置按钮颜色,所以我最终更改了背景和标题颜色以使用 while 按钮,以便它们变得可见。感谢您的帮助。
  • 令人惊讶的是,Apple 创建的这些 API 设计得如此糟糕。每样东西都是半熟的。
  • navigationBar 外观更改在AppDelegate 中似乎不起作用。似乎无论我做什么,我都无法在MFMailComposeViewController 中获得navigationBar 的tintColor,以兑现我的设置。已经尝试过上面显示的内容,直接在 compose 控制器本身上更改这些相同的属性,并构建类的扩展并覆盖 viewDidLoad。有没有人找到可靠的方法来做到这一点?
  • 发现我的问题。有关详细信息,请参阅此答案。 stackoverflow.com/a/47503809/10162227
【解决方案2】:

我的最终答案是来自这里的第一条评论:How to change color of MFMailComposeViewController texts and button images? 你必须在哪里设置

mail.view.tintColor = .green

然后我的按钮显示为绿色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多