开发者

How change the current image's button on Click?

开发者 https://www.devze.com 2023-04-12 19:32 出处:网络
In my file .h : -(IBAction)Boutton:(id)sender; In my file .m : -(IBAction)Boutton:(id)sender { UIImage *btnImage1 = [UIImage imageNamed:@\"x.png\"];

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

精彩评论

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

关注公众号