if([button backgroundColor]==[UIColor yellowcolor]){
[taggedB开发者_高级运维tn setBackgroundColor:[UIColor redColor]];
}
----------
if([button backgroundColor]==[UIColor yellowcolor])
How can I check button's color?
Thanks for your helping
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
Use the CGColor
property of UIColor
:
if (CGColorEqualToColor([button backgroundColor].CGColor, [UIColor yellowcolor].CGColor) {
Have a look here.
精彩评论