Search code examples
iphoneios4xcode4

How to check button's color?


if([button backgroundColor]==[UIColor yellowcolor]){
    [taggedBtn setBackgroundColor:[UIColor redColor]];
}

----------

if([button backgroundColor]==[UIColor yellowcolor])

How can I check button's color?

Thanks for your helping


Solution

  • You need to use [button.backgroundColor isEqual:[UIColor yellowColor]

    If you use == you compare the pointers. With [UIColor yellowColor] you create a new instance. And that one won't be the same as the backgroundColor of your button. ;-)

    Sandro Meier