使用UIImageView展现来自网络的图片

摘要:
@“.png”];NSImage*image=[[NSImagealloc]initWithContentsOfFile:@“http:image];path];//让UIImageView响应单击事件UIImageView*imgView=[[UIImageView alloc]init WithFrame:imgView.userInteractionEnabled=YES;
本文转载至 http://www.cnblogs.com/chivas/archive/2012/05/21/2512324.html

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展现来自网络的图片》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Nodemcu的GPIO接口介绍(ZT)设置导航栏标题颜色及字体大小下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

把微信小程序异步API转为Promise,简化异步编程

把微信小程序异步API转化为Promise。用Promise处理异步操作有多方便,谁用谁知道。 微信官方没有给出Promise API来处理异步操作,而官方API异步的又非常多,这使得多异步编程会层层回调,代码一复杂,回调起来就想砸电脑。 于是写了一个通用工具,把微信官方的异步API转化为Promise,方便处理(多)异步操作。 你可以这样用: 准备转化后...

win下配置nginx

1.下载:http://nginx.org/en/download.html 2.在安装目录cmd: start nginx.exe 启动nginx 3.修改默认运行端口80(nginx.conf):  HTTP 数据分发 修改配置文件nginx.conf相应节点: 修改完后重启服务: nginx -s reload TCP 数据分发:  ng...

attrib命令

attrib指令的格式和常用参数为:ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [[drive:] [path] filename] [/S [/D]]   +    设置属性。   -     清除属性。   R    只读文件属性。   A    存档文件属性。   S    系统文件属性。   H ...

高德地图API之公交路线

引入插件 AMap.Transfer <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>map</title> <script type="text/javascri...

CALayer 进阶

转载自:http://www.cofcool.net/development/2015/06/19/ios-study-note-eight-CALayer-info/ The CALayer class manages image-based content and allows you to perform animations on that con...

iOS 拨打电话(解决openURL延迟和不同方法比较)

转载请注明出处!!! iOS拨打电话有三种方法。 注意:最新的iOS12上测试 三种方法效果没有区别 也不要开线程 第一种: NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"]; [[UIApplication sharedApplic...