Change title color of navigation bar in MFMailComposeViewController in iOS 12 not working

情到浓时终转凉″ 提交于 2019-11-30 01:28:18

I tried all the way to change the title color, however it doesn't work

Before presenting the mailcomopser controller

I changed the background color to white

and buttons color to black

Here is the code below:

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)

In your AppDelegate.swift file in the didFinishLaunchingWithOptions launchOptions block

TRY THIS:

    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
Євген Поліщук

titleView still works fine. Just create view with label in story board like this, with such font, as U need and set it as title view.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!