开发者

How to check button's color?

开发者 https://www.devze.com 2023-03-25 03:26 出处:网络
if([button backgroundColor]==[UIColor yellowcolor]){ [taggedB开发者_高级运维tn setBackgroundColor:[UIColor redColor]];
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

精彩评论

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

关注公众号