UIImageView详解
来源:互联网 发布:淘宝祛痘产品 编辑:程序博客网 时间:2024/06/05 12:07
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 =[[UIImageView alloc] 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详解
- UIImageView控件使用详解
- UIImageView控件使用详解
- UIImageView控件使用详解
- UIImageView基础详解
- ios UIImageView详解
- UIImageView的contentMode属性详解
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- Oracle 11g RAC INS-06006 Passwordless SSH connectivity not set up between the following node(s) 解决方法
- 一种注册表沙箱的思路、实现——研究Reactos中注册表函数的实现4
- android 内存泄露 小结
- Hibernate入门BLOG[十五、Hibernate的乐观锁与悲观锁]
- js操作table
- UIImageView详解
- linux的swapper_pg_dir的初始化
- GNU ARM汇编--(八)s3c2440的watchdog
- BMP文件格式详解
- Android的EidtText的一些研究,持续更新中!!!!!
- android源码解析 ---- camera 照相机 摄像机
- 多线程写图像文件的一点小测试(Boost + Gual)
- android notification
- Dialog背景透明无边框