开发者

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];

}


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.


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)
{
...
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜