Why does +[UIColor whiteColor] not equal another white?

断了今生、忘了曾经 提交于 2019-12-01 22:08:12

"UIColor" isn't always based on RGBA values.

There are different color spaces that UIColor works with, such as CMYK colors and, in the case of white color, you can get a white color via [UIColor colorWithWhite:alpha:].

I suspect [UIColor whiteColor] in your case is going to equal [UIColor colorWithWhite:1.0 alpha:1.0].

One likely explanation is the color space used by the distinct color instances. White can be represented in many distinct domains, or spaces. An equality comparison may be negative if the color spaces are not equal, or if the spaces are not easy to transform to another space (e.g. transforming an absolute representation to device representation may result in a loss of information).

Color representations are complex; accurate "comparisons" deserve multiple methods to compare colors and many should include render destinations.

Charlie Price

[UIColor whiteColor] does not produce an RGB color space object -- it is in a grayscale color space. Try

NSLog(@"color is %@", [UIColor whiteColor]);

Very annoying.

You can, of course, make a white color with RGB all equal to 1.0, but it isn't the same color object as [UIColor whiteColor].

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