how to change navigationitem title color

前端 未结 11 1331
南旧
南旧 2021-01-30 12:35

I think all day to change the navigation Bar title color, but it doesn\'t work. this is my code:

var user: User? {
    didSet {
        navigationItem.title = us         


        
11条回答
  •  孤城傲影
    2021-01-30 13:27

    you can just add this line of code in your AppDelegate in the func

    didFinishLaunchingWithOptions
    

    Code you will add to change title color:

    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor(red: 0.7415059209, green: 0.5448099971, blue: 0.5051562786, alpha: 1)]
    

    you can add this line as well if you wanna change the backButton color

      UINavigationBar.appearance().tintColor = #colorLiteral(red: 0.7415059209, green: 0.5448099971, blue: 0.5051562786, alpha: 1)
    

    Finally you can add this line to change the background color:

    UINavigationBar.appearance().barTintColor = #colorLiteral(red: 0.2000651062, green: 0.1960035861, blue: 0.2000851929, alpha: 1)
    

    Note: You can change the values dependent on the color you want and have a happy coding day

提交回复
热议问题