UIColor vs IB color (color profile issue)

别来无恙 提交于 2019-12-19 02:42:20

问题


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:

  1. Why standard "Dark Gray Color" is different when set in IB and in code?
  2. How to use Generic RGB profile in code, so I can match color values with Interface Builder?

回答1:


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....



来源:https://stackoverflow.com/questions/41456073/uicolor-vs-ib-color-color-profile-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!