Изменить цвет заголовка панели навигации в MFMailComposeViewController в iOS 12 не работает - программирование
Подтвердить что ты не робот

Изменить цвет заголовка панели навигации в MFMailComposeViewController в iOS 12 не работает

Как я могу изменить цвет заголовка UINavigationBar в MFMailComposeViewController в iOS 12?

Это то, что я делаю:

import MessageUI

extension MFMailComposeViewController {
    open override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isTranslucent = false
        navigationBar.isOpaque = false
        navigationBar.barTintColor = .white
        navigationBar.tintColor = .white
        navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    }
}

В iOS 10 работает:

ios 10

В iOS 11 работает:

ios 11

В iOS 12 не работает:

ios 12

4b9b3361

Ответ 1

Я пытался полностью изменить цвет заголовка, однако это не работает

Я изменил цвет фона на белый

и кнопки цвет черный

Вот код ниже:

UINavigationBar.appearance().setBackgroundImage(UIImage(), for: UIBarPosition.any, barMetrics: UIBarMetrics.default)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().barTintColor = UIColor.white
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().clipsToBounds = false
UINavigationBar.appearance().backgroundColor = UIColor.white
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.black], for: .normal)
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.black], for: .highlighted)
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .disabled)
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.black], for: .selected)

enter image description here

Ответ 2

Я надеюсь, что это помогает всем, у меня была эта проблема и я застрял около 2 часов, но вуаля, я получил решение. вам не нужно переопределять функции, упомянутые rmaddy, это может привести к неожиданным результатам. Решение состоит в том, чтобы использовать внешний вид UINavigation до создания экземпляра MFMailComposeViewController, и свойство будет работать так, как должно было быть. Я добавляю пример кода, как я его использовал. Надеюсь, поможет :)

КОД

  func setNavigatinAppearanceToBlack() {

    UINavigationBar.appearance().titleTextAttributes =
        [NSFontAttributeName: AppFont.appFont(fontType: .bold, size: 18)]
    let attributes:Dictionary = [NSFontAttributeName :
        AppFont.appFont(fontType: .bold, size: 18), NSForegroundColorAttributeName : UIColor.black]
    UIBarButtonItem.appearance().setTitleTextAttributes(attributes as [String : Any]?, for: .normal)

}
func sendEmailToPrimaryEmail(){

    if (MFMailComposeViewController.canSendMail()){

        setNavigatinAppearanceToBlack() // here change the property as you need
        let mailComposerVC = MFMailComposeViewController()
        mailComposerVC.mailComposeDelegate = self
        mailComposerVC.setToRecipients([(self.contactDetail?.response?.data?.contactDetail?.contactEmail1)!])
        mailComposerVC.view.tintColor = UIColor.black
        mailComposerVC.setMessageBody("", isHTML: false)
        self.present(mailComposerVC, animated: true, completion: nil)
    }else{
        self.showAlert(message: "Looks like, your email is not configured!")
    }
}

Ответ 3

В файле AppDelegate.swift в блоке launchOptions didFinishLaunchingWithOptions

ПОПРОБУЙ ЭТО:

    let navigationBarAppearace = UINavigationBar.appearance()
    navigationBarAppearace.barTintColor = .blue //your desired color
    navigationBarAppearace.tintColor = .white //your button etc color 
    navigationBarAppearace.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] //your Title Text color

Ответ 4

Положите это на свой файл AppDelegate.swift на приложение func()

UINavigationBar.appearance().barTintColor = UIColor(red:0.04, green:0.45, blue:0.42, alpha:1.00)
    UINavigationBar.appearance().tintColor = UIColor.white
    UITabBar.appearance().tintColor = UIColor(red: 0.224, green: 0.698, blue: 0.667, alpha: 1.0)

    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]

Ответ 5

titleView по-прежнему работает нормально. Просто создайте вид с надписью в раскадровке таким образом, с таким шрифтом, как вам нужно, и установите его как вид заголовка.

if let view = Bundle.main.loadNibNamed("WTitleView", owner: self, options: nil)?.first as? UIView {
            navigationItem.titleView = view
} 

like this