SDWebImage

类引用有5个 分别是以下几个 

SDImageCache  图片异步缓存

SDWebImageDownloader   图片异步下载 

SDWebImageDownloaderOperation Class Reference  图片异步下载操作

  • SDWebImageManager 图片管理
    • SDWebImagePrefetcher 图片预处理
    • 一、SDImageCache  图片异步缓存
      概述
    • SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn’t add 
    • unnecessary latency to the UI.
    • SDImageCache只要包括维护一个内存缓存和一个可选的磁盘缓存。磁盘高速缓存的写操作被执行异步所以它不会增加不必要的等待时间到用户界面。


    • property
      属性 

    • @property (assign, nonatomic) NSInteger maxCacheAge   以秒为单位 图片保存在内存中的最长时间

    •   maxMemoryCost property    保存在存储器中像素的总和 
        maxCacheAge  maxCacheSize property   在内存中能够存储图片的最大容量 以比特为单位
      + sharedImageCache

    • 创建一个新的缓存空间
      – initWithNamespace:

    • 添加一个只读的缓存路径
      – addReadOnlyCachePath:
      – storeImage:forKey:
      – storeImage:forKey:toDisk:
      – storeImage:recalculateFromImage:imageData:forKey:toDisk:
      – queryDiskCacheForKey:done:
      – imageFromMemoryCacheForKey:
      – imageFromDiskCacheForKey:

    • 删除图片 
      – removeImageForKey:
      – removeImageForKey:withCompletion:
      – removeImageForKey:fromDisk:
      – removeImageForKey:fromDisk:withCompletion:
      – clearMemory       清除缓存
      – clearDiskOnCompletion:
      – clearDisk      清除磁盘
      – cleanDiskWithCompletionBlock:   block回调 在清除磁盘后的操作
      – cleanDisk          清除磁盘
      – getSize          获取缓存的大小  比特  如果想要获取M  可以与1024相除
      – getDiskCount      在磁盘中缓存图片的个数
      – calculateSizeWithCompletionBlock:
      – diskImageExistsWithKey:completion:
      – diskImageExistsWithKey:
      – cachePathForKey:inPath:
      – defaultCachePathForKey:    默认缓存的路径


  • [objc] view plain copy
    1. @interface TableViewController (){  
    2.     SDImageCache *cache;  
    3. }  
    [objc] view plain copy
    1. //  创建缓存实例  
    2.     cache = [[SDImageCache alloc]init];  
    3.     //  获取sdwebimage的共享单例  
    4.     cache =  [SDImageCache sharedImageCache];  
    5.       
    6.     // 在内存缓存保留的最长时间 以秒为单位计算 为了检测 设置为5秒  
    7.     cache.maxCacheAge = 30;  
    8.     //  在内存中能够存储图片的最大容量 以比特为单位 这里设为1024 也就是1M  
    9.     cache.maxCacheSize = 1024;  
    10.     //  保存在存储器中像素的总和  
    11.     cache.maxMemoryCost = 1000;  
    12.       
    13.       
    14.     //  下载  
    15.     // 创建实例  
    16.     downloaderImage = [SDWebImageDownloader sharedDownloader];  
    17.     //  设置下载的用户名和密码  
    18.     downloaderImage.username = @"yun";  
    19.     downloaderImage.password = @"0628";  
    20.     //  设置下载超时时间  
    21.     downloaderImage.downloadTimeout = 5;  
    22.       
    23.     //  当前的下载量 只读属性  
    24.     NSInteger downloader  = [downloaderImage currentDownloadCount];  
    25.     NSString *downloaderCount = [NSString stringWithFormat:@"%ld",(long)downloader];  
    26.     NSLog(@"downloaderCount = %@",downloaderCount);  
    27.       
    28.       
    29.     NSInteger macDownloader = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;  
    30.     NSLog(@",(long)macDownloader = %ld",(long)macDownloader);  

    [objc] view plain copy
    1. //  清除磁盘中的缓存  
    2. [cache cleanDisk];  
    3. //  清除缓存的存储  
    4. [cache clearMemory];  
    5. [self.tableView reloadData];  


  • [objc] view plain copy
    1. //  异步加载图片并缓存  
    2.    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage imageNamed:@"placeho.jpg"]]; 

你可能感兴趣的:(第三方库,SDWebImage)