网络热恋之SDWebImage
SDWebImage-master 是一个非常强大的三方。
当需要应用SDWeb时把文件夹里的SDWebImage文件夹放入工程里。
在需要使用网络获取图片的文件里进入头文件#import "UIImageView+WebCache.h"即可使用相应的api。
首先最基本的方法展示(仅获取图片)
#import "ViewController.h"
#import "UIImageView+WebCache.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; NSString * urlString = [NSString stringWithFormat:@"http://localhost/tupian.jpg"]; NSURL * url = [NSURL URLWithString:urlString]; UIImageView * imageView = [[UIImageView alloc]init]; imageView.frame = CGRectMake(, , CGRectGetWidth(self.view.frame), ); [imageView sd_setImageWithURL:url]; [self.view addSubview:imageView]; } @end
*温馨提示:SDWebImage-master可以在github上下载。*
防止网速差刷不出来图片,会出现留白现象,为此加了占位图片;图片不唯一可以自己配置;
#import "ViewController.h"
#import "UIImageView+WebCache.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; NSString * urlString = [NSString stringWithFormat:@"http://localhost/tupian.jpg"]; NSURL * url = [NSURL URLWithString:urlString]; UIImageView * imageView = [[UIImageView alloc]init]; imageView.frame = CGRectMake(, , CGRectGetWidth(self.view.frame), ); [imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"图片名称"]]; [self.view addSubview:imageView]; } @end
//
// ViewController.m
// CX-SDWebImage-master
// #import "ViewController.h"
#import "UIImageView+WebCache.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; NSString * urlString = [NSString stringWithFormat:@"http://localhost/tupian.jpg"]; NSURL * url = [NSURL URLWithString:urlString]; UIImageView * imageView = [[UIImageView alloc]init]; imageView.frame = CGRectMake(, , CGRectGetWidth(self.view.frame), ); [imageView sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { NSLog(@"%@",image);
//枚举
NSLog(@"%ld",(long)cacheType); NSLog(@"%@",imageURL); }]; [self.view addSubview:imageView]; }
/*
结果
2016-03-18 13:12:18.091 CX-SDWebImage-master[4626:283982] <UIImage: 0x7fe8a3f0d900>, {250, 250}
2016-03-18 13:12:18.092 CX-SDWebImage-master[4626:283982] 1
2016-03-18 13:12:18.092 CX-SDWebImage-master[4626:283982] http://localhost/tupian.jpg
*/ @end
网络热恋之SDWebImage的更多相关文章
- 网络&热恋NSURLConnection代理及GET¥POST请求
1.NSURLConnection代理下载设置在本地的身骑着白马MP3 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional ...
- 网络热恋之NSURLSession
// // ViewController.m // NSURLSession代理简介 #import "ViewController.h" @interface ViewContr ...
- 网络热恋之json解析
现在的app开发很少有用到XML解析的了,主流的则是JSON. // // ViewController.m // CX-JSON解析(三方JSONKit-master) #import " ...
- 网络热恋之XML解析
XML 可扩展标记语言 用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言 易读性高,编码手写难度小,数据量大 NSXMLPars ...
- Swift版音乐播放器(简化版),swift音乐播放器
这几天闲着也是闲着,学习一下Swift的,于是到开源社区Download了个OC版的音乐播放器,练练手,在这里发扬开源精神, 希望对大家有帮助! 这个DEMO里,使用到了 AudioPlayer(对音 ...
- Swift版音乐播放器(简化版)
这几天闲着也是闲着,学习一下Swift的.于是到开源社区Download了个OC版的音乐播放器,练练手,在这里发扬开源精神. 希望对大家有帮助! 这个DEMO里.使用到了 AudioPlayer(对音 ...
- IOS 网络-深入浅出(一 )-> 三方SDWebImage
首要我们以最为常用的UIImageView为例介绍实现原理: 1)UIImageView+WebCache: setImageWithURL:placeholderImage:options: 先显 ...
- IOS 网络浅析-(十三 SDWebImage 实用技巧)
IOS 网络浅析-(十三 SDWebImage 实用技巧) 首先让我描述一下为了什么而产生的实用技巧.(在TableView.CollectionView中)当用户所处环境WiFi网速不够快(不能立即 ...
- IOS 网络浅析-(六 网络图片获取之三方SDWebImage)
网络图片获取是大多数app所能用到的,由于实际app开发中原生api很少用到,在这里就先不介绍了,以后有时间会给大家介绍.这篇文章会给大家介绍一个三方-SDWebImage.SDWebImage 是一 ...
随机推荐
- Eclipse窗口总是在最前的解决办法
Eclipse窗口总是在最前的解决办法 状况: Eclipse在偶然的情况下,会莫名其妙地保持在窗口的最前面,一直保持在最前:然后alt + tab,或者鼠标点击其他窗口.想切换/激活其他窗口时,根本 ...
- CHARFORMAT2 structure
CHARFORMAT2 structure 包含在丰富的编辑控件中的字符格式设置的信息.charformat2是微软丰富的编辑CHARFORMAT结构2扩展.微软丰富的编辑2允许您使用结构与em_ge ...
- C#解压缩文件
代码: #region 解压 /// <summary> /// 解压 /// </summary> public void UnZip(string zipPath, str ...
- LINQ多个操作嵌套实现
获取集合,需要使用多个条件Where,排序OrderBy,查询Select一起. 先来分步实现: source code: string[] stringArray = { "hgdgh&q ...
- jQuery动态设置样式List item
前段时间,Insus.NET有修改一个功能<激活当前视图菜单高亮呈现>http://www.cnblogs.com/insus/p/5287093.html 今天Insus.NET想改用另 ...
- Linux下快速设定ip bond
在计算机网路普及的初期,很多OS系统都使用的为单网卡方式,即一个网卡使用一个IP地址.随着网络要求的不断提高,我们可以对多个网卡进行绑定聚合当一个逻辑网络接口来使用,从而大幅提升服务器的网络吞吐(I/ ...
- WCF Throttling 限流的三道闸口
WCF Throttling 限流的三道闸口 一.WCF Throttling 流量限制简介 我们期望WCF服务端能够处理尽可能多的并发请求,但是资源是有限的,服务不可能同时处理无限多的并发请求,如 ...
- EasyUI-扩大在DataGrid显示次网格的行
一.下载并引用:datagrid-detailview.js脚本文件 二.添加UrlInfo控制器,添加Index页面代码如下: @{ Layout = null; } <!DOCTYPE ht ...
- ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️html,js随笔。❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️
a标签本身的文字居中. a{ display:block; text-align:center; } 设置div1在另一个div2里居中,(写了左边margin 就别写右边了不然ie6有毛病,当然本身 ...
- tmpfs:一种基于内存的文件系统
tmpfs是一种基于内存的文件系统, tmpfs有时候使用rm(物理内存),有时候使用swap(磁盘一块区域).根据实际情况进行分配. rm:物理内存.real memery的简称? 真实内存就是电脑 ...