SDWebImage實現圖片展示、快取、清除快取

有稜角的圓發表於2016-05-20

1.

/*

圖片顯示

*/

        [self.imageView sd_setImageWithURL:[NSURL URLWithString:urlString]];
        
        [self imageCachesWithUrl:[NSURL URLWithString:model.mediumLogo]];

2.
/*
圖片快取
*/
-(void)imageCachesWithUrl:(NSURL*)url{


    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    
    [manager downloadImageWithURL:url options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
        NSLog(@"顯示當前進度");
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        
        NSLog(@"下載完成");
    }];

 

}

3./*

清理圖片快取

*/

float tmpSize = [[SDImageCache sharedImageCache] getSize];
                
                [[SDImageCache sharedImageCache] clearDisk];
               // float tmpSize = [[SDImageCache sharedImageCache]checkTmpSize];
               // [[SDWebImageManager sharedManager].imageCache clearMemory];
                
               // float tmpSize= [SDWebImageManager sharedManager].imageCache.getSize;
                NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理快取(%.2fM)",tmpSize/1000000] : [NSString stringWithFormat:@"清理快取(%.2fK)",tmpSize/1000];
                NSLog(@"%@",clearCacheName);

相關文章