第三方框架研究——SDWebImage使用,图片加载和缓存
框架功能:这个类库提供一个UIImageView类别以支持加载来自网络的图片。具有缓存管理、异步下载、同一个URL下载次数控制和优化等特征
使用框架:
第一步,下载SDWebImage,导入工程。github托管地址 https://github.com/rs/SDWebImage
第二步,在需用用到的地方导入头文件 #import "UIImageView+WebCache.h"
第三步,调用sd_setImageWithURL:方法缓存图片(网上说这是新方法,老方法是setImageWithUrl)
代码部分:
//设置一个ImageView
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
imgView.backgroundColor = [UIColor blackColor];
[self.view addSubview:imgView];
//图片缓存代码
NSURL *url = [NSURL URLWithString:@"http://d.hiphotos.baidu.com/zhidao/pic/item/562c11dfa9ec8a13e028c4c0f603918fa0ecc0e4