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:
- Why standard "Dark Gray Color" is different when set in IB and in code?
- How to use Generic RGB profile in code, so I can match color values with Interface Builder?
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 usingStoryboard
and programmatically becauseStoryboard
usessRGB IEC61966-2.1
orGeneric RGB
Color Profile
by default and when you set it programmatically so it takesDevice RGB
Color profile
because Device RGB iOS devices out thereiPhones, 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 anyColor Profile
because it will takeDevice 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....