问题描述
这真的很奇怪。将 + [UIColor redColor]
与我创建的红色进行比较,得出的结果相同,但是将 + [UIColor whiteColor]
进行比较
This is something really strange. Comparing +[UIColor redColor]
with a red I create myself gives an equal result, but comparing +[UIColor whiteColor]
to another white does not.
// This test passes.
XCTAssertEqualObjects([UIColor redColor],
[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0],
@"Red should equal red.");
// While this test fails!
XCTAssertEqualObjects([UIColor whiteColor],
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
@"White should equal white.");
在扩展 UIColor
的同时
有人可以帮我一下吗?
推荐答案
UIColor
并不总是基于RGBA值。
"UIColor
" isn't always based on RGBA values.
UIColor处理不同的颜色空间,例如CMYK颜色;对于白色,您可以通过。
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:]
.
我怀疑 [UIColor whiteColor]
在您的情况下等于 [UIColor colorWithWhite :1.0 alpha:1.0]
。
I suspect [UIColor whiteColor]
in your case is going to equal [UIColor colorWithWhite:1.0 alpha:1.0]
.
这篇关于+ [UIColor whiteColor]为什么不等于另一种白色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!