Color difference between drawRect and Interface Builder?

假如想象 提交于 2019-11-29 14:06:00

问题


Simply, I have 2 views in interface builder, one is set to the color 99,99,99 using the RGB sliders in interface builder.

The other view is colored programmatically to achieve a certain shape. I fill it using:

//Obviously, this is in drawRect.
[[UIColor leadColor] set];
CGContextEOFillPath(myContext);

//And this is a category on UIColor
+ (UIColor *)leadColor {
    return [UIColor colorWithWhite:99/255.0 alpha:1.0];
}

The result:

Why does this difference exist??


EDIT: (unecessary drawRect Code removed)


EDIT2:

So, here I am lying to myself .. "Interface builder showed RGB 99,99,99 as 80,80,80. I bet it offsets the number by 19." >.> ... A desperate man using Xcode thinks crazy stuff like this .. The result:

PERFECT!!, but why???? Another Xcode bug? I found like 10 of those in the past month ...


回答1:


I finally reached the fine-tuning stage of this app, and had to solve this issue, so, I searched and easily found the solution:

How do I enter RGB values into Interface Builder?

Illustration:




回答2:


colorWithWhite uses grayscale space, and a color of 99 in grayscale space doesn't map to a color of (99,99,99) in RGB space.

So in order to get the same result as in Interface Builder, you need to use RGB space. Replace your call to colorWithWhite with this:

[UIColor colorWithRed:99/255.0 green:99/255.0 blue:99/255.0 alpha:1.0]


来源:https://stackoverflow.com/questions/10779297/color-difference-between-drawrect-and-interface-builder

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