How to compare UIColors?

4thSpace picture 4thSpace · Jun 9, 2009 · Viewed 51.3k times · Source

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.

Answer

Steven Canfield picture Steven Canfield · Jun 9, 2009

Have you tried [myColor isEqual:someOtherColor] ?