I'm using XCode 8.2.1. I just learned about color profiles and that RGB values are not universal. But still can't understand how to make it right in code. In Interface Builder I selected predefined "Dark Gray Color" for a label. It is (85, 85, 85) in Generic RGB profile. Also in code I set another label color to [UIColor darkGrayColor]. I expected them to have the same color, but they are different.
I used method
- (BOOL)getRed:(nullable CGFloat *)red green:(nullable CGFloat *)green blue:(nullable CGFloat *)blue alpha:(nullable CGFloat *)alpha
to get RGB values. For the label which color was set in IB I see that values are actually (104,104,104) which correspond to values in IB when I switch to Device RGB profile. So it seems that in code Device RGB profile is used.
So my questions are:
Hello Jesse please see answer below:
Why standard "Dark Gray Color" is different when set in IB and in code?
Standard Dark Gray Color
is different using Storyboard
and programmatically because Storyboard
uses sRGB IEC61966-2.1
or Generic RGB
Color Profile
by default and when you set it programmatically so it takes Device RGB
Color profile
because Device RGB iOS devices out there iPhones, iPads
have different characteristics in terms of their display color profiles .
How to use Generic RGB profile in code, so I can match color values with Interface Builder?
When you set UIColor
programmatically so you have no choice to select any Color Profile
because it will take Device RGB
Color Profile
.
If you want to make it same, So in your storyboard select your Colour picker, Open settings and change it to Device RGB
See below screen shot for Color Profile Setting using Storyboard:
I hope it will help you....
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