I find that when you set a view's backgroundColor in xib, the color displayed is distinctly different from when you set backgroundColor programmatically.
Here's an example.
I have two views in this simple demo. I set the upper view's backgroundColor in xib, like this:
The hex color value is 0x1BA9BA. Then I set the lower view's backgroundColor programmatically with the same hex color value. I use the following code:
NSInteger hexValue = 0x1ba9ba;
self.testView.backgroundColor = [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0
green:((float)((hexValue & 0xFF00) >> 8)) / 255.0
blue:((float)(hexValue & 0xFF))/255.0
alpha:1.0];
The result is as follows:
As you can see, there's a clear difference in color. What am I missing here?
I applied your RGB sliders to the first view and your code to the second view and the colors are absolutely identical (to my eye) in the simulator; this is a screen shot from the simulator:
However, I entered those numbers into the color picker (27, 169, 186) when the color picker's color space was set to Generic RGB. If I switch to sRGB and then enter those numbers, I can reproduce your problem. So it is a color space issue after all; just start with the color space set to Generic RGB and now the numbers will match up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With