Change the color of iOS Navigation Bar

前端 未结 9 2113
挽巷
挽巷 2020-12-07 13:57

I\'m trying to change the color of my navigator bar but I found that it\'s only impossible if the navigator is the root one.

I\'m trying this:

self.n         


        
9条回答
  •  悲&欢浪女
    2020-12-07 14:31

    Updated for Swift 3

        UINavigationBar.appearance().barTintColor = .black
        UINavigationBar.appearance().tintColor = .white
        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
        UINavigationBar.appearance().isTranslucent = false
    

    Swift 4

        UINavigationBar.appearance().barTintColor = .black
        UINavigationBar.appearance().tintColor = .white
        UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
        UINavigationBar.appearance().isTranslucent = false
    

    Swift 5

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

提交回复
热议问题