比较按钮值

时间:2012-07-18 16:53:57

标签: objective-c

我认为我有两个按钮。

[button1 setBackgroundImage:image1 forState:UIControlStateNormal];
[button2 setBackgroundImage:image2 forState:UIControlStateNormal];

如何比较这些按钮中的两个图像?我试过了:

if (button1.imageView.image.CGImage == button2.imageView.image.CGImage)
{
   NSLog(@"equal");
}
else
{
  NSLog(@"not equal");
}

它不起作用:(。

任何建议? 感谢帮助 Yayo

1 个答案:

答案 0 :(得分:0)

试试这个

if ([[button1 backgroundImageForState:UIControlStateNormal] isEqual:[button2 backgroundImageForState:UIControlStateNormal]])