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
Try comparing against the UIImage returned by the backgroundImageForState: method instead of the UIButton imageView's image property...
if ([[twitterButton backgroundImageForState:UIControlStateNormal] isEqual:twitterImage1])
ie.,
if ([[twitterButton backgroundImageForState:UIControlStateNormal] isEqual:[UIImage imageNamed@"myImage.png"]]){
// Button has a background image named 'myImage.png'
}else{
// Button has not a background image named 'myImage.png'
}
See the UIButton class reference for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With