Color difference between UINavigationBar Tint Color and rest of app in IOS
Asked Answered
I

1

11

This is my design in Sketch:

enter image description here

Sketch says that the blue color is 70,164,239.

So I have the following code for my tab:

UINavigationBar.appearance().barTintColor = UIColor(red: 70.0/255.0, green: 164.0/255.0, blue: 239.0/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.clearColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]

And the following for the view underneath (inside an action):

self.two_buttons_view.backgroundColor = UIColor(red: 70.0/255.0, green: 164.0/255.0, blue: 239.0/255.0, alpha: 1.0)

But look what's going on, the Navigation Bar color is always a little lighter than the color of the view. With this light blue there's only a slight difference but if I go with a darker blue it gets much more noticeable. It appears that the navigation bar's colors are never as rich as the rest of pages views are:

enter image description here

Inelegant answered 25/7, 2016 at 18:0 Comment(0)
H
31

The tintColor is a tint color. It combines with the translucency (is that a word?) of the bar, along with what's behind the bar, to give some other resulting color.

If you want full control over the actual color of a navigation bar, set its translucent to false and then give it a background image consisting of a rectangle of the desired color - and no tint color.

Hilariohilarious answered 25/7, 2016 at 18:5 Comment(3)
Thanks, @matt. UINavigationBar.appearance().translucent = false was all that was needed in my case, it looks superb now even when just setting the color itself via the tint colorInelegant
In Swift 3 this has changed to: UINavigationBar.appearance().isTranslucent = falseInelegant
You don't need to give it a background image. You can just set its backgroundColor.Canning

© 2022 - 2024 — McMap. All rights reserved.