TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2018 |
Maintained by CoderZhuXH.
==============
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *url = self.dataArray[indexPath.row];
/**
* 参数1:图片URL
* 参数2:imageView 宽度
* 参数3:预估高度(此高度仅在图片尚未加载出来前起作用,不影响真实高度)
*/
return [XHWebImageAutoSize imageHeightForURL:[NSURL URLWithString:url] layoutWidth:[UIScreen mainScreen].bounds.size.width-16 estimateHeight:200];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
DemoVC1Cell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if(!cell)
{
cell = [[DemoVC1Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSString *url = self.dataArray[indexPath.row];
//加载网络图片使用SDWebImage
[cell.imgView sd_setImageWithURL:[NSURL URLWithString:url] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
/** 缓存image size */
[XHWebImageAutoSize storeImageSize:image forURL:imageURL completed:^(BOOL result) {
/** reload */
if(result) [tableView xh_reloadDataForURL:imageURL];
}];
}];
return cell;
}
/**
* Get image height
*
* @param url imageURL
* @param layoutWidth layoutWidth
* @param estimateHeight estimateHeight(default 100)
*
* @return imageHeight
*/
+(CGFloat)imageHeightForURL:(NSURL *)url layoutWidth:(CGFloat)layoutWidth estimateHeight:(CGFloat )estimateHeight;
/**
* Get image size from cache,query the disk cache synchronously after checking the memory cache
*
* @param url imageURL
*
* @return imageSize
*/
+(CGSize )imageSizeFromCacheForURL:(NSURL *)url;
/**
* Store an imageSize into memory and disk cache
*
* @param image image
* @param url imageURL
* @param completedBlock An block that should be executed after the imageSize has been saved (optional)
*/
+(void)storeImageSize:(UIImage *)image forURL:(NSURL *)url completed:(XHWebImageAutoSizeCacheCompletionBlock)completedBlock;
/**
* Get reload state from cache,query the disk cache synchronously after checking the memory cache
*
* @param url imageURL
*
* @return reloadState
*/
+(BOOL)reloadStateFromCacheForURL:(NSURL *)url;
/**
* Store an reloadState into memory and disk cache
*
* @param state reloadState
* @param url imageURL
* @param completedBlock An block that should be executed after the reloadState has been saved (optional)
*/
+(void)storeReloadState:(BOOL)state forURL:(NSURL *)url completed:(XHWebImageAutoSizeCacheCompletionBlock)completedBlock;
/**
Reload tableView
@param url imageURL
*/
-(void)xh_reloadDataForURL:(NSURL *)url;
/**
Reload collectionView
@param url imageURL
*/
-(void)xh_reloadDataForURL:(NSURL *)url;
XHWebImageAutoSize 使用 MIT 许可证,详情见 LICENSE 文件