我如何比较 UIButton backgroundImage 标题?
在 UIButton 上,我设置像这样的背景图像
[twitterButton setBackgroundImage:twitterImage forState:UIControlStateNormal];
twitterImage 的类型为 UIImage
现在,在单击任何按钮的代码中的某处,我使用标签值设置 twitterButton 图像
[twitterButton setBackgroundImage:twitterImage1 forState:UIControlStateNormal];
我的问题是如何比较 twitterButton 的图像?
这种情况不起作用 if([twitterbutton.imageView.image isEqual:twitterImage1])
请帮忙
On a UIButton I set background images like this
[twitterButton setBackgroundImage:twitterImage forState:UIControlStateNormal];
twitterImage is of type UIImage
Now somewhere in the code on any button clicked I set twitterButton image using tag value
[twitterButton setBackgroundImage:twitterImage1 forState:UIControlStateNormal];
My problem is How would I compare the image of twitterButton ?
this condition is not working if([twitterbutton.imageView.image isEqual:twitterImage1])
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试与 backgroundImageForState: 方法返回的 UIImage 进行比较,而不是 UIButton imageView 的图像属性...
即,
请参阅 UIButton 类参考了解更多信息。
Try comparing against the UIImage returned by the backgroundImageForState: method instead of the UIButton imageView's image property...
ie.,
See the UIButton class reference for more information.
您无法比较UIButton的backgroundImage。您使用一些引用变量
you can't compare backgroundImage of UIButton's.you set the backgroundImage using some reference variable
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html
尝试使用 UIButton 的 currentBackgroundImage 属性。这将为您提供当前的背景图像。 UIButton参考
Try using the
currentBackgroundImage
property of UIButton. This will give you the current background image.. UIButton Reference我认为这很昂贵,但您可以尝试将图像转换为 nsdata,然后使用 isEqualToData。
编辑
I think this is expensive but you can try converting the images into nsdata and then use the isEqualToData.
Edit