博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(iphone开发)从网络读取图片并显示
阅读量:4556 次
发布时间:2019-06-08

本文共 834 字,大约阅读时间需要 2 分钟。

NSString *urlString = @"http://img4.bitauto.com/autoalbum/files/20100226/003/201002260944098032_1155951_4.jpg";
NSURL *url = [NSURL URLWithString:urlString];
NSData *myData = [NSData dataWithContentsOfURL: url];
UIImage *myImage = [UIImage imageWithData: myData];
UIImageView *myImageView = [[UIImageView alloc] initWithImage: myImage];
UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(myImage.size.width, myImage.size.height;
[self.view addSubview: myScrollView];
[myScrollView release];
[myScrollView addSubview: myImageView];
[myImageView release];
如果返回url是nil,则用下面的代码代替:
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

转载于:https://www.cnblogs.com/top5/archive/2012/03/23/2414336.html

你可能感兴趣的文章
SQL2005查询所有表的大小
查看>>
Shell 正则表达式
查看>>
Docker run命令参数整理
查看>>
qt-opencv配置mingw编译器
查看>>
CSS之Medial Queries的另一用法:实现IE hack的方法
查看>>
oo第三单元总结
查看>>
linux-CentOS6.4下安装oracle11g详解
查看>>
实力为王 八年DBA经验谈
查看>>
2-sat 问题 【例题 Flags(2-sat+线段树优化建图)】
查看>>
ext3.2 右击动态添加node的treepanel
查看>>
Database links
查看>>
1035 插入与归并(25 分)
查看>>
STL中排序函数的用法(Qsort,Sort,Stable_sort,Partial_sort,List::sort)
查看>>
如何解决php 生成验证码图片不显示问题
查看>>
PHP,javascript实现大文件上传
查看>>
c#图像处理算法学习
查看>>
webApi之FromUri和FromBody区别
查看>>
【SoapUI】http接口测试
查看>>
各种工具网站
查看>>
数据库事务
查看>>