1决采、常用的方法
//常用方法一
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
//例如:
NSURL *url = [NSURL URLWithString:app.icon];
UIImage *placeholder = [UIImage imageNamed:@"placeholder"];
[cell.imageView sd_setImageWithURL:url placeholderImage:placeholder];
//常用方法二
//參數(shù)三:SDWebImageOptions
//SDWebImageRetryFailed :下載失敗后脱羡,會(huì)重新繼續(xù)下載
//SDWebImageLowPriority :正在進(jìn)行UI交互操作時(shí)罚渐,停止內(nèi)部的下載操作
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
//例如
SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageLowPriority;
[cell.imageView sd_setImageWithURL:url placeholderImage:placeholder options:options];
//常用方法三
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
//例如:
[cell.imageView sd_setImageWithURL:url placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(@"----圖片加載完畢---%@", image);
}];
//常用方法四
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock ;
//例如:
SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageLowPriority;
[cell.imageView sd_setImageWithURL:url placeholderImage:placeholder options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { // 這個(gè)block可能會(huì)被調(diào)用多次
NSLog(@"下載進(jìn)度:%f", (double)receivedSize / expectedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(@"----圖片加載完畢---%@", image);
}];
2捏膨、內(nèi)存處理秧均,當(dāng)app收到內(nèi)存警告時(shí)
//該方法寫在AppDelegate.m文件中
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
SDWebImageManager *mgr = [SDWebImageManager sharedManager];
// 1.取消正在下載的操作
[mgr cancelAll];
// 2.清除內(nèi)存緩存
[mgr.imageCache clearMemory];
}