SDWebImage實現圖片展示、緩存、清除緩存


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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM