点击目标c中的按钮更改图像 [英] change image on click of button in objective c

查看:90
本文介绍了点击目标c中的按钮更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的.xib文件中放了3个按钮(分别为btn1,btn2,btn3),最初我给他们提供了默认图片,first.png

i draged 3 button in my .xib file (btn1,btn2,btn3 respectively) and initially i given default image to them, first.png

现在用户点击btn1,btn1的图像应该从first.png更改为second.png ..

now when user clicks on btn1, image of btn1 should change from first.png to second.png..

当用户选择btn2时,btn2的图像应该从first.png更改to second.png,并将btn1的图像再次更改为默认first.png,以便用户知道他已点击第二个按钮。

and when user selects on btn2, image of btn2 should change from first.png to second.png, and also change image of btn1 to default again first.png, so that user came to know he has clicked 2nd button.

应如何我这样做了吗?

提前致谢!!

Thanks In Advance !!

推荐答案

您必须设置按钮动作方法的代码

You have to set button action method code

-(IBAction)btnClked:(id)sender
{
  [btn1 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateNormal];
  [btn2 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateNormal];
  [btn3 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateNormal];

  UIButton *btn=(UIButton *)sender;

  [btn setImage:[UIImage imageNamed:@"second.png"] forState:UIControlStateNormal];
}

这篇关于点击目标c中的按钮更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆