change image on click of button in objective c(单击目标 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 中的按钮更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:单击目标 c 中的按钮更改图像


基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01