开发者

How to check button's color?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜