Why is + [UIColor whiteColor] not equal to another white?

This is really weird. Comparison +[UIColor redColor]with red I create myself, gives an equal result, but comparison +[UIColor whiteColor]with 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.");

While I am expanding UIColorwith some useful additions, this fact can be very annoying.

Can anyone shed some light on this for me?

+3
source share
3 answers

" UIColor" is not always based on RGBA values.

There are various color spaces that UIColor works with, for example, CMYK colors, and in the case of white, you can get white through [UIColor colorWithWhite:alpha:].

, [UIColor whiteColor] [UIColor colorWithWhite:1.0 alpha:1.0].

+4

, . . , , (, ).

; "" , .

+2

[UIColor whiteColor] does not create an object of the RGB color space - it is in the color space in shades of gray. Try

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

Very annoying.

You can, of course, make the white color with RGB equal to 1.0, but this is not the same color object as [UIColor whiteColor].

+2
source

All Articles