Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I compare UIButton backgroundImage title?

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

like image 980
Tariq Avatar asked Apr 01 '11 09:04

Tariq


1 Answers

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.

like image 70
mmccomb Avatar answered Sep 18 '22 14:09

mmccomb