Ria
Ria

Reputation: 31

Change button image on click event

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

Answers (3)

user3459648
user3459648

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

Paresh Hirpara
Paresh Hirpara

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

Cyrille
Cyrille

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

Related Questions