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

后端 未结 3 1652
迷失自我
迷失自我 2020-12-24 12:00

How can I change the title color of UINavigationBar in MFMailComposeViewController in iOS 12?

This is what I am doing:

相关标签:
3条回答
  • 2020-12-24 12: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)
    

    0 讨论(0)
  • 2020-12-24 12:24

    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
    
    0 讨论(0)
  • 2020-12-24 12:35

    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
    } 
    

    like this

    0 讨论(0)
提交回复
热议问题