UIButton:用两张图片---代码中自己用的模版之二
来源:互联网 发布:东莞金域名苑名林居 编辑:程序博客网 时间:2024/06/05 10:34
我们在用UIButton的时候,想要两张图片,一张时正常显示的,一张是在点击时显示的,这个该怎么实现呢?
下面时我的实现方式,如有别的方式,请大家一起分享出来,共同学习....
NSString *path = nil; UIImage *image = nil; path = [[NSBundle mainBundle] pathForResource:@"menubtn1" ofType:@"png"]; image = [UIImage imageWithContentsOfFile:path]; _gameBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _gameBtn.frame = CGRectMake(180, 670, image.size.width, image.size.height); [_gameBtn setImage:image forState:UIControlStateNormal];//这个图片是在布点击时响应 path = nil; image = nil; path = [[NSBundle mainBundle] pathForResource:@"menubtn1_1" ofType:@"png"]; image = [UIImage imageWithContentsOfFile:path]; [_gameBtn setImage:image forState:UIControlStateHighlighted];//图片在点击的时候响应 [_gameBtn addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_gameBtn]; path = nil; image = nil;
下面还有响应事件的代码:
-(IBAction)ButtonClick:(id)sender{ UIButton *whichOne = (UIButton *)sender; if (_gameBtn == whichOne) { NSLog(@"You Clicked _gameBtn"); }}
- UIButton:用两张图片---代码中自己用的模版之二
- 代码中自己用的模版之一
- 一句代码搞定 UIButton 的图片与文字布局
- php 教你写自己的模版引擎二
- UIButton中显示的图片和标题位置的设置
- UIButton中显示的图片和标题位置的设置
- 关于UIButton的图文混排之图片
- 定制UIButton中文字和图片的位置
- UIButton中图片与文字的位置设置
- UIButton中设置图片与标题位置的解决方案
- ios学习之UIbutton的纯代码实现
- UIButton 的图片自动拉伸
- 猫猫学iOS之UIButton一行代码重写图片和标题位置
- 猫猫学iOS之UIButton一行代码重写图片和标题位置源代码分享
- 自己的LaTeX简历模版
- 定制自己的vue模版
- 自己写的”图片轮换效果“代码
- 模版方法--行为型模式之二:类的关系
- Linux输入子系统分析 -- 输入子系统初始化
- 这些年的项目管理心得
- C# Socket编程基础入门
- MemcacheDB, Tokyo Tyrant, Redis performance test
- 数字图像处理的招聘公司
- UIButton:用两张图片---代码中自己用的模版之二
- 原子操作基本内容计算机操作系统进程
- vim 分割窗口[转]
- 枚举类
- mysql支持调用begin end来执行代码块吗?
- Newsvendor model
- 《第十三周实验报告任务3》
- Spring事务传播性与隔离级别
- 设置Cookie的生命周期