使用UIImageView展现来自网络的图片
2015-12-25 22:53
543 查看
UIImageView:可以通过UIImage加载图片赋给UIImageView,加载后你可以指定显示的位置和大小。
1、初始化
UIImageView*imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(0.0,45.0,300,300)];
imageView.image=[UIImageimageNamed:@"a.png"];//加载入图片
[self.viewaddSubView:image];
[imageViewrelease];
//imageNamed方法是不能通过路径进行加载图片的,此方式容易引起发生内存警告从而导致自动退出的问题。
//最好是通过直接读取文件路径[UIImageimageWithContentsOfFile]解决掉这个问题.
NSImage*image=[[NSImagealloc]initWithContentsOfURL:(NSURL*)];
NSImage*image=[[NSImagealloc]initWithContentsOfFile:(NSString*)];
如:
1、》》》
UIImage*image=[[UIImagealloc]initWithData:[NSDatadataWithContentsOfURL:[NSURLURLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
UIImageView*imageView=[[UIImageViewalloc]initWithImage:image];
2、》》》
NSString*path=[[NSBundlemainBundle]pathForResource:@”icon”ofType:@”png”];
NSImage*myImage=[UIImageimageWithContentsOfFile:path];
//让一个UIImageView响应点击事件
UIImageView*imgView=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0,320,44)];
imgView.userInteractionEnabled=YES;
UITapGestureRecognizer*singleTap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(onClickImage)];
[imgViewaddGestureRecognizer:singleTap];
[singleTaprelease];
-(void)onClickImage{
//here,dowhateveryouwanttodo
NSLog(@"imageviewisclicked!");
}
相关文章推荐
- Android 下载网络图片 简单Demo
- 【转载】千万级规模高性能、高并发的网络架构经验分享
- Reachability(判断网络是否连接)
- TCP中异常关闭链接的意义 异常关闭的情况
- C#之网络
- bzoj1070[SCOI2007]修车(费用流)
- Meta http-equiv属性与HTTP头的Expires中(Cache-control)详解
- Java语言实现的简单网络爬虫复习
- iOS:iOS9关于HTTP和HTTPS的问题
- android之旅9 网络编程与消息队列
- ping lwip网络协议栈 分析(二)
- bzoj3931[CQOI2015]网络吞吐量
- TCP 长连接与短连接
- IOS网络图片缓存详解
- SDN 网络中的路由规则 (一)
- ping lwip网络协议栈 分析(一)
- https和http的区别
- HTTP 与 HTTPS的区别。
- opencv中VideoCapture的使用——打开网络摄像头/图像序列
- Android热门网络框架Volley详解