iOS 网络图片加载库
SDWebImage 一款超级好用的网络图片加载库
集成方式
pod 'SDWebImage', '~> 5.0'
使用方式
#import <SDWebImage/SDWebImage.h>
[imageView sd_setImageWithURL:[NSURL URLWithString:@"图片地址"]
placeholderImage:[UIImage imageNamed:@"占位图名字"]];
加载gif
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
SDAnimatedImage *animatedImage = [SDAnimatedImage imageNamed:@"image.gif"];
imageView.image = animatedImage;
使用Blocks,采用这个方案可以在网络图片加载过程中得知图片的下载进度和图片加载成功与否
[imageView sd_setImageWithURL:[NSURL URLWithString:@"图片地址"] placeholderImage:[UIImage imageNamed:@"占位图"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { //... completion code here ... }];
取图片的缓存大小
清理内存,磁盘缓存
[SDImageCache sharedImageCache] getSize];
清理内存,磁盘缓存
[[SDImageCache sharedImageCache] clearMemory];
常见问题及demo地址:点击这里