聲明處: UIImageView+Webcache.h
概述
整合UIImageView和SDWebImage進(jìn)行異步下載和緩存遠(yuǎn)程圖片。
UITableViewCell子類的使用范例:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
// Here we use the provided sd_setImageWithURL: method to load the web image
// Ensure you use a placeholder image otherwise cells will be initialized with no image
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder"]];
cell.textLabel.text = @"My Text";
return cell;
}
任務(wù)
- sd_setImageWithURL:
- sd_setImageWithURL:placeholderImage:
- sd_setImageWithURL:placeholderImage:options:
- sd_setImageWithURL:completed:
- sd_setImageWithURL:placeholderImage:completed:
- sd_setImageWithURL:placeholderImage:options:completed:
- sd_setImageWithURL:placeholderImage:options:progress:completed:
- sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed:
- sd_setAnimationImagesWithURLs:
- sd_cancelCurrentAnimationImagesLoad
實例方法
sd_cancelCurrentAnimationImagesLoad
- (void)sd_cancelCurrentAnimationImagesLoad
sd_setAnimationImagesWithURLs:
- (void)sd_setAnimationImagesWithURLs:(nonnull NSArray<NSURL*> *)arrayOfURLs
討論
下載一個圖片數(shù)組然后在一個動畫循環(huán)中顯示他們收毫。
參數(shù)
arrayOfURLs
一個NSURL數(shù)組攻走。
聲明處
UIImageView+WebCache.h
sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed:
- (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock
討論
根據(jù)一個url和可選的默認(rèn)圖片來設(shè)置圖片視圖的圖片。
下載是異步和會緩存的此再。
注意: 進(jìn)度塊是在后臺隊列執(zhí)行的昔搂。
參數(shù)
url
圖片的url。
placeholder
圖片初始化內(nèi)容输拇,直到圖片請求完成摘符。
options
下載圖片時使用的選項〔叻停可能的值詳見SDWebImageOptions逛裤。
progressBlock
圖片下載中執(zhí)行的塊。
completedBlock
操作完成時調(diào)用塊猴抹。這個塊沒有返回值带族,帶有參數(shù),第一個參數(shù)為請求的UIImage蟀给,如果發(fā)生錯誤這個值為nil蝙砌。第二個參數(shù)為一個NSError的內(nèi)容。第三個參數(shù)是一個Boolean值坤溃,指示圖片是從本地緩存中恢復(fù)拍霜,還是從網(wǎng)絡(luò)獲取。第四個參數(shù)為原始的圖片url薪介。
聲明處
UIImageView+WebCache.h
sd_setImageWithURL:
- (void)sd_setImageWithURL:(nullable NSURL *)url
討論
根據(jù)一個url來設(shè)置圖片視圖的圖片。
下載是異步和會緩存的越驻。
參數(shù)
url
圖片的url汁政。
聲明處
UIImageView+WebCache.h
sd_setImageWithURL:completed:
- (void)sd_setImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock
討論
根據(jù)一個url來設(shè)置圖片視圖的圖片道偷。
下載是異步和會緩存的。
注意: 進(jìn)度塊是在后臺隊列執(zhí)行的记劈。
參數(shù)
url
圖片的url勺鸦。
completedBlock
操作完成時調(diào)用塊。這個塊沒有返回值目木,帶有參數(shù)换途,第一個參數(shù)為請求的UIImage,如果發(fā)生錯誤這個值為nil刽射。第二個參數(shù)為一個NSError的內(nèi)容军拟。第三個參數(shù)是一個Boolean值,指示圖片是從本地緩存中恢復(fù)誓禁,還是從網(wǎng)絡(luò)獲取懈息。第四個參數(shù)為原始的圖片url。
聲明處
UIImageView+WebCache.h
sd_setImageWithURL:placeholderImage:
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder
討論
根據(jù)一個url和默認(rèn)圖片來設(shè)置圖片視圖的圖片摹恰。
下載是異步和會緩存的辫继。
參數(shù)
url
圖片的url。
placeholder
圖片初始化內(nèi)容俗慈,直到圖片請求完成姑宽。
同見- sd_setImageWithURL:placeholderImage:options:
聲明處
UIImageView+WebCache.h
sd_setImageWithURL:placeholderImage:completed:
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder completed:(nullable SDExternalCompletionBlock)completedBlock
討論
根據(jù)一個url和默認(rèn)圖片來設(shè)置圖片視圖的圖片。
下載是異步和會緩存的闺阱。
參數(shù)
url
圖片的url炮车。
placeholder
圖片初始化內(nèi)容,直到圖片請求完成馏颂。
completedBlock
操作完成時調(diào)用塊姆另。這個塊沒有返回值享钞,帶有參數(shù),第一個參數(shù)為請求的UIImage,如果發(fā)生錯誤這個值為nil即寡。第二個參數(shù)為一個NSError的內(nèi)容。第三個參數(shù)是一個Boolean值鼠锈,指示圖片是從本地緩存中恢復(fù)岭粤,還是從網(wǎng)絡(luò)獲取。第四個參數(shù)為原始的圖片url派昧。
聲明處
UIImageView+WebCache.h
sd_setImageWithURL:placeholderImage:options:
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options
討論
根據(jù)一個url,默認(rèn)圖片和自定義選項來設(shè)置圖片視圖的圖片黔姜。
下載是異步和會緩存的。
參數(shù)
url
圖片的url蒂萎。
placeholder
圖片初始化內(nèi)容秆吵,直到圖片請求完成。
options
下載圖片時使用的選項五慈∧杉牛可能的值詳見SDWebImageOptions主穗。
聲明處
UIImageView+WebCache.h
sd_setImageWithURL:placeholderImage:options:completed:
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options completed:(nullable SDExternalCompletionBlock)completedBlock
討論
根據(jù)一個url,默認(rèn)圖片和自定義選項來設(shè)置圖片視圖的圖片。
下載是異步和會緩存的毙芜。
參數(shù)
url
圖片的url忽媒。
placeholder
圖片初始化內(nèi)容,直到圖片請求完成腋粥。
options
下載圖片時使用的選項晦雨“澹可能的值詳見SDWebImageOptions。
completedBlock
操作完成時調(diào)用塊。這個塊沒有返回值,帶有參數(shù),第一個參數(shù)為請求的UIImage堕担,如果發(fā)生錯誤這個值為nil。第二個參數(shù)為一個NSError的內(nèi)容。第三個參數(shù)是一個Boolean值,指示圖片是從本地緩存中恢復(fù),還是從網(wǎng)絡(luò)獲取洽议。第四個參數(shù)為原始的圖片url混稽。
聲明處
UIImageView+WebCache.h
sd_setImageWithURL:placeholderImage:options:progress:completed:
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock
討論
根據(jù)一個url,默認(rèn)圖片和自定義選項來設(shè)置圖片視圖的圖片痘系。
下載是異步和會緩存的昭雌。
注意: 進(jìn)度塊是在后臺隊列執(zhí)行的烛卧。
參數(shù)
url
圖片的url佛纫。
placeholder
圖片初始化內(nèi)容,直到圖片請求完成总放。
options
下載圖片時使用的選項呈宇。可能的值詳見SDWebImageOptions局雄。
progressBlock
圖片下載中執(zhí)行的塊甥啄。
completedBlock
操作完成時調(diào)用塊。這個塊沒有返回值哎榴,帶有參數(shù)型豁,第一個參數(shù)為請求的UIImage,如果發(fā)生錯誤這個值為nil尚蝌。第二個參數(shù)為一個NSError的內(nèi)容迎变。第三個參數(shù)是一個Boolean值,指示圖片是從本地緩存中恢復(fù)飘言,還是從網(wǎng)絡(luò)獲取衣形。第四個參數(shù)為原始的圖片url。
聲明處
UIImageView+WebCache.h
// END 呵呵噠。一直在復(fù)制黏貼谆吴。接口是寫的好暗乖础!