iOS开发第三方框架SDWebImage的使用步骤(图片未显示问
2016-05-05 本文已影响657人
Courage_SC
一、SDWebImage的使用
1.依赖的框架
-
ImageIO.framework
-
MapKit.framework
2.UIImageView下载图片需要的头文件:UIImageView+WebCache.h
3.调用方法下载图片
// url是图片路径
// placeholder是占位图片(正在下载图片时,暂时显示的图片)
// options是缓存策略
-
(void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
-
(void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options
4.缓存策略-SDWebImageOptions (最主要的,添加选项防止图片未显示)
//最主要的,添加选项防止图片未显示
[self.imgView sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"图片加载中"] options:SDWebImageLowPriority | SDWebImageRetryFailed];
默认是开启了硬盘\内存缓存的
-
SDWebImageRetryFailed 下载失败了会再次尝试下载
-
SDWebImageLowPriority 当UIScrollView等正在滚动时,延迟下载图片(放置scrollView滚动卡)
-
SDWebImageCacheMemoryOnly 只缓存到内存中,不缓存到硬盘上
-
SDWebImageProgressiveDownload 图片会一点一点慢慢显示出来(就像浏览器显示网页上的图片一样)
-
SDWebImageRefreshCached 将硬盘缓存交给系统自带的NSURLCache去处理,当同一个URL对应的图片经常更改时可以用这种策略