I'd like to check the color set for a background on a UIImageView. I've tried:
if(myimage.backgroundColor == [UIColor greenColor]){
...}
else{
...}
but that doesn't work, even when I know the color is green, it always falls into the else part.
Also, is there a way to output the current color in the debug console.
p [myimage backgroundColor]
and
po [myimage backgroundColor]
don't work.
This might be a bit too late, but CoreGraphics has an easier API to achieve this:
Like the documentation says:
This solves a lot trouble and leaking/custom algorithms.
What about:
Why not add the extension with equatable protocol? This answer is using the solution of Nicolas Miari. So, if you like this answer, please be welcome to like his answer (second from the top)
The comment of Zoul: Be careful when comparing colors this way, because they have to be in the same color model to be considered equal. For instance, #ffffff does not equal [UIColor whiteColor]
UIColor extension
Have you tried
[myColor isEqual:someOtherColor]
?