views:

903

answers:

2

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.

+5  A: 

Have you tried [myColor isEqual:someOtherColor] ?

Steven Canfield
Thanks. What is the difference with isEqualTo? Also, do you know how to display it in the debugger?
4thSpace
By the way: 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]`.
zoul
+1  A: 
if([myimage.backgroundColor isEqual:[UIColor greenColor]])
Nikolai Ruhe