Joe
Joe

Reputation: 447

How change the current image's button on Click?

In my file .h :

-(IBAction)Boutton:(id)sender;

In my file .m :

-(IBAction)Boutton:(id)sender
{ 

    UIImage *btnImage1 = [UIImage imageNamed:@"x.png"];
    [sender setImage:btnImage1 forState:UIControlStateNormal];

}

With this code i can change the image of my clicked button (sender).

The question is, how can I change the images of the others buttons (not the sender one) ?

For example if (sender.tag == 4) i would like To have something like :

-(IBAction)Boutton:(id)sender
{ 

    UIImage *btnImage1 = [UIImage imageNamed:@"x.png"];
    [sender setImage:btnImage1 forState:UIControlStateNormal];

    UIImage *btnImage2 = [UIImage imageNamed:@"Y.png"];

    [Boutton:(1) setImage:btnImage2 forState:UIControlStateNormal];
    [Boutton:(2) setImage:btnImage2 forState:UIControlStateNormal];
    [Boutton:(3) setImage:btnImage2 forState:UIControlStateNormal];

}

Upvotes: 1

Views: 6984

Answers (3)

Diaa Den
Diaa Den

Reputation: 1214

choose the button and assign the image you want then from the utilities bar change the state config to Highlighted then assign the on click image

see the screen shot below

screen shot

Upvotes: 0

Can Ürek
Can Ürek

Reputation: 661

The question is, how can I change the images of the others buttons (not the sender one) ?

Use tag parameters of UIButton.

UIButton *btn = (UIButton *)sender;

if(btn.tag == 1)
{
...
}

Upvotes: 0

Jean-Denis Muys
Jean-Denis Muys

Reputation: 6842

Simply link the other buttons to outlets of your UIViewController subclass. So that from -(IBAction)Boutton:(id)sender you can change their image by accessing them through their properties.

Upvotes: 1

Related Questions