注册

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地址:点击这里


2 个评论

问下大佬,下载进度是由哪个参数来看的,cacheType?
zuyu

zuyu 回复 费城

- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options progress:(nullable SDImageLoaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock; 调用这个api ,progressBlock就是进度的回调

要回复文章请先登录注册