1.使用UImageView+WebCache加载图片
[imageView sd_setImageWithURL:[NSURLURLWithString:@"图片URL"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[imageView sd_animatedGIFNamed:[NSURLURLWithString:@"图片URL"];//加载GIF图片
2.使用Blocks,采用这个方案可以在网络图片加载过程中得知图片的下载进度和图片加载成功与否
[imageView sd_setImageWithURL:[NSURL URLWithString:@"图片URL"] placeholderImage:[UIImage imageNamed:@"placeholder.png"] completed:^(UIImage image,NSError error, SDImageCacheType cacheType,NSURL*imageURL) {
... completion code here ...
}];
3.使用SDWebImageManager,SDWebImageManager为UIImageView+WebCache category的实现提供接口。
SDWebImageManager manager = [SDWebImageManager sharedManager] ;
[manager downloadImageWithURL:imageURL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
} completed:^(UIImage image, NSError error, SDImageCacheType cacheType, BOOL finished, NSURL imageURL) {
if(image) {
//do something with image
} }];
4.获取SDWebImage的磁盘缓存大小
[SDImageCache sharedImageCache] getSize];
5.清理内存缓存,清理内存中缓存的图片资源,释放内存资源。
[[SDImageCache sharedImageCache] clearMemory];
6.有了清理内存缓存,自然也有清理磁盘缓存的接口
[[SDImageCache sharedImageCache] clearDisk];