Reputation: 31
I want to change button image. As when i click on the button it will change it's image and after the click the button will return in its normal form.I want to know how to implement this? Please help me.
Upvotes: 1
Views: 461
Reputation: 361
UIImage *buttonImage = [UIImage imageNamed:@"image.png"];
[sender setImage:buttonImage forState:UIControlStateHighlighted];
UIImage *buttonImage1 = [UIImage imageNamed:@"image.png"];
[sender setImage:buttonImage1 forState:UIControlStateNormal];
Upvotes: 1
Reputation: 487
first fix the Backgroudimage is @"image1.jpeg"
in xib
, then
- (IBAction)mybutton:(id)sender
{
[_buttonrefrence setBackgroundImage:[UIImage imageNamed:@"download.jpeg"] forState:UIControlStateHighlighted];
}
Upvotes: 0
Reputation: 25144
You can customize the "highlighted" state of your button right in Interface Builder, or use this code:
[self.button setImage:[UIImage imageNamed:@"normal"] forState:UIControlStateNormal];
[self.button setImage:[UIImage imageNamed:@"pressed"] forState:UIControlStateHighlighted];
Upvotes: 0