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

查看:20
本文介绍了单击目标 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 变为 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.

我应该怎么做?

提前致谢!

推荐答案

你要设置按钮动作方法代码

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天全站免登陆