Navigation bar color is wrong

Hi,


I'm having a really weird problem. Brand new project, using a UINavigationController. I want to set the background color of my navigation bar to match the background color of my root view controller.


I thought that this was the right way to do it:


  [[UINavigationBar appearance] setTranslucent:NO];
  [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0x2d/255.0 green:0x55/255.0 blue:0x97/255.0 alpha:1.0]];


However, this generates a navigation bar with a color value of #234185 instead of the expected #2D5597. What is the explanation for this, and how do I fix it?


Thanks,

Frank

How are you measuring the resulting color? In iOS 10 and later, color values are specified in the sRGB color space (documentation). For example, the difference of color spaces causes Digital Color Meter on macOS to report slightly different values (when set to "Display native values"). I myself have been confused when measuring the color of UI elements in the simulator with Digital Color Meter.

You're right. I'm just discovering this now; the fact that an RGB value set in Interface Builder is "Generic RGB" by default, whereas the RGB value used by UIColor is sRGB.


I find this change absolutely astonishing. Not being able to rely on colors having the same color feels like not having solid ground under your feet anymore. I'm imagining developers everywhere being confused by this, not to mention the fights they're going to have with their graphic artists after they insist that they put in the exact color the artist asked for but the color comes out wrong.


Not to mention, the existing apps. I'm sure I have hundreds of places in older apps where I matched colors from Interface Builder with UIColors declared in code. I'm picturing all my apps recompiling with all kinds of weird wrong colors.


It's pretty crazy if you ask me.

I had this same issue, it turned out that translucent was set to true on the navigation bar.
Navigation bar color is wrong
 
 
Q