UIImageView控件使用详解
来源:互联网 发布:使徒行者电影票房数据 编辑:程序博客网 时间:2024/05/22 06:59
UIImageView:可以通过UIImage加载图片赋给UIImageView,加载后你可以指定显示的位置和大小。
1、初始化
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0,45.0,300,300)];
imageView.image = [UIImage imageNamed:@"a.png"];//加载入图片
[self.view addSubView:image];
[imageView release];
//imageNamed方法是不能通过路径进行加载图片的,此方式容易引起发生内存警告从而导致自动退出的问题。
//最好是通过直接读取文件路径[UIImage imageWithContentsOfFile]解决掉这个问题.
NSImage *image = [[NSImage alloc]initWithContentsOfURL:(NSURL *)];
NSImage *image = [[NSImage alloc]initWithContentsOfFile:(NSString *)];
如:
1、》》》
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
2、》》》
NSString *path = [[NSBundle mainBundle]pathForResource:@”icon”ofType:@”png”];NSImage *myImage = [UIImage imageWithContentsOfFile:path];
//让一个UIImageView响应点击事件
UIImageView *imgView =[[UIImageViewalloc] initWithFrame:CGRectMake(0,0,320, 44)];
imgView.userInteractionEnabled=YES;
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(onClickImage)];
[imgView addGestureRecognizer:singleTap];
[singleTap release];
-(void)onClickImage{
// here, do whatever you wantto do
NSLog(@"imageview is clicked!");
}
- UIImageView控件使用详解
- UIImageView控件使用详解
- UIImageView控件使用详解
- iOS控件使用之UIImageView
- UIImageView控件
- UIImageView详解
- UIImageView详解
- UIImageView详解
- UIImageView 使用
- iOS开发之六:常用控件--UIImageView的使用
- UIKit框架-高级控件:6.UIPickerView与UIImageView结合使用
- UIKit框架-高级控件:8.UIPickerView, UILabel, UIImageView结合使用
- iOS--Quartz2D使用(自定义UIImageView控件、绘制基本图形)
- UI控件 - UIImageView
- 【 UIImageView图片控件】
- IOS UI控件 - UIImageView
- UI控件--UIImageView
- UIImageView基础详解
- 电商的穷途末路?
- 页面和 designer.cs 代码不同步的解决办法
- SQL Convert的用法
- Working Set 的使用
- MVC MvcPager 普通分页
- UIImageView控件使用详解
- 收集些好文!
- libevent介绍
- Android中的ActivityManager: Error: Activity class {XXX} does not exist的问题解决
- GRETA库在VS 2005环境下的编译经验
- 搜索引擎不收录页面的常见原因
- PostgreSQL 安装问题
- 微软c语言循环递归笔试题分析
- 使用ASP.NET建立并控制客户端脚本的四种方法