SDWebImage
2015-10-14 10:47
351 查看
类引用有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 plaincopy
@interface TableViewController (){
SDImageCache *cache;
}
[objc]
view plaincopy
// 创建缓存实例
cache = [[SDImageCache alloc]init];
// 获取sdwebimage的共享单例
cache = [SDImageCache sharedImageCache];
// 在内存缓存保留的最长时间 以秒为单位计算 为了检测 设置为5秒
cache.maxCacheAge = 30;
// 在内存中能够存储图片的最大容量 以比特为单位 这里设为1024 也就是1M
cache.maxCacheSize = 1024;
// 保存在存储器中像素的总和
cache.maxMemoryCost = 1000;
// 下载
// 创建实例
downloaderImage = [SDWebImageDownloader sharedDownloader];
// 设置下载的用户名和密码
downloaderImage.username = @"yun";
downloaderImage.password = @"0628";
// 设置下载超时时间
downloaderImage.downloadTimeout = 5;
// 当前的下载量 只读属性
NSInteger downloader = [downloaderImage currentDownloadCount];
NSString *downloaderCount = [NSString stringWithFormat:@"%ld",(long)downloader];
NSLog(@"downloaderCount = %@",downloaderCount);
NSInteger macDownloader = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;
NSLog(@",(long)macDownloader = %ld",(long)macDownloader);
[objc]
view plaincopy
// 清除磁盘中的缓存
[cache cleanDisk];
// 清除缓存的存储
[cache clearMemory];
[self.tableView reloadData];
[objc]
view plaincopy
// 异步加载图片并缓存
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage imageNamed:@"placeho.jpg"]];
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 plaincopy
@interface TableViewController (){
SDImageCache *cache;
}
[objc]
view plaincopy
// 创建缓存实例
cache = [[SDImageCache alloc]init];
// 获取sdwebimage的共享单例
cache = [SDImageCache sharedImageCache];
// 在内存缓存保留的最长时间 以秒为单位计算 为了检测 设置为5秒
cache.maxCacheAge = 30;
// 在内存中能够存储图片的最大容量 以比特为单位 这里设为1024 也就是1M
cache.maxCacheSize = 1024;
// 保存在存储器中像素的总和
cache.maxMemoryCost = 1000;
// 下载
// 创建实例
downloaderImage = [SDWebImageDownloader sharedDownloader];
// 设置下载的用户名和密码
downloaderImage.username = @"yun";
downloaderImage.password = @"0628";
// 设置下载超时时间
downloaderImage.downloadTimeout = 5;
// 当前的下载量 只读属性
NSInteger downloader = [downloaderImage currentDownloadCount];
NSString *downloaderCount = [NSString stringWithFormat:@"%ld",(long)downloader];
NSLog(@"downloaderCount = %@",downloaderCount);
NSInteger macDownloader = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;
NSLog(@",(long)macDownloader = %ld",(long)macDownloader);
[objc]
view plaincopy
// 清除磁盘中的缓存
[cache cleanDisk];
// 清除缓存的存储
[cache clearMemory];
[self.tableView reloadData];
[objc]
view plaincopy
// 异步加载图片并缓存
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage imageNamed:@"placeho.jpg"]];
相关文章推荐
- Python中pip安装非PyPI官网第三方库的方法
- Python安装第三方库的3种方法
- FMDB:中的用法介绍
- Facebook Paper使用的第三方库
- 添加第三方库出现library not found for - "解决办法
- iOS开发常用第三方库
- iOS开发实战:SDWebImage深度解析
- SDWebImage使用——一个可管理远程图片加载的类库
- 使用第三方库时路径配置的原理
- sdwebImage 如何清除缓存
- Qt Creator 添加第三方库
- iOS多线程编程及简单封装图片下载
- JNI 如何使用dlopen,dlsym调用第三方自定义的 .so库(包括JNI->JNI)
- Xcode6编译SDWebImage报错解决方法(SDWebImageDownloaderOperation.m错误)
- iOS常用第三方类库
- 开源项目和开源类库
- iOS开发系列--网络开发
- SDWebImage学习
- 关于升级xcode 5.1编译失败问题
- 安装第三方库rsa遇到的问题