{"id":21802872,"url":"https://github.com/coderzhuxh/xhwebimageautosize","last_synced_at":"2025-04-10T00:19:14.612Z","repository":{"id":45701202,"uuid":"73878121","full_name":"CoderZhuXH/XHWebImageAutoSize","owner":"CoderZhuXH","description":"网络图片尺寸、高度自适应/适配 - 支持异步缓存imageSize , 支持动态刷新界面","archived":false,"fork":false,"pushed_at":"2020-01-03T11:44:09.000Z","size":5813,"stargazers_count":273,"open_issues_count":8,"forks_count":60,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T22:06:21.628Z","etag":null,"topics":["objcective-c","pod"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CoderZhuXH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-16T03:02:09.000Z","updated_at":"2024-09-14T23:47:44.000Z","dependencies_parsed_at":"2022-08-28T19:31:12.867Z","dependency_job_id":null,"html_url":"https://github.com/CoderZhuXH/XHWebImageAutoSize","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderZhuXH%2FXHWebImageAutoSize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderZhuXH%2FXHWebImageAutoSize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderZhuXH%2FXHWebImageAutoSize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderZhuXH%2FXHWebImageAutoSize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoderZhuXH","download_url":"https://codeload.github.com/CoderZhuXH/XHWebImageAutoSize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131473,"owners_count":21052854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["objcective-c","pod"],"created_at":"2024-11-27T11:33:59.360Z","updated_at":"2025-04-10T00:19:14.586Z","avatar_url":"https://github.com/CoderZhuXH.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# XHWebImageAutoSize\n\n### 网络图片尺寸/高度自适应解决方案\n\n[![AppVeyor](https://img.shields.io/appveyor/ci/gruntjs/grunt.svg?maxAge=2592000)](https://github.com/CoderZhuXH/XHWebImageAutoSize)\n[![Version Status](https://img.shields.io/cocoapods/v/XHWebImageAutoSize.svg?style=flat)](http://cocoadocs.org/docsets/XHWebImageAutoSize)\n[![Support](https://img.shields.io/badge/support-iOS%207%2B-brightgreen.svg)](https://github.com/CoderZhuXH/XHWebImageAutoSize)\n[![Pod Platform](https://img.shields.io/cocoapods/p/XHWebImageAutoSize.svg?style=flat)](http://cocoadocs.org/docsets/XHWebImageAutoSize/)\n[![Pod License](https://img.shields.io/cocoapods/l/XHWebImageAutoSize.svg?style=flat)](https://github.com/CoderZhuXH/XHWebImageAutoSize/blob/master/LICENSE)\n\n==============\n\n### 前言:\n*   1.iOS开发中,常碰到网络图片需要做尺寸适配(使显示出来的图片不变形)\n*   2.最好的解决方案是:后台把图片的分辨率拼接在图片的URL地址中,我们截取获得分辨率,从而根据宽高比,来适配imageView尺寸.\n*   3.但往往有些时候由于各种原因,图片分辨率后台那边加不上去,没办法只好我们自己来解决了.\n*   4.XHWebImageAutoSize就是解决3中的这种情况.\n\n### 特性:\n* 1.异步缓存网络图片尺寸,优先从缓存中获取图片尺寸.\n* 2.UITableView,UICollectionView UI动态更新.\n\n### 技术交流群(群号:537476189).\n\n\n## 效果\n![](/ScreenShot/Demo1.png) ![](/ScreenShot/Demo2.png) ![](/ScreenShot/Demo3.png)\n\n\n## 使用方法\n\n####    1.此处以在UITableView中使用,UITableViewCell上仅有一个UIImageView为例(其他示例详见DEMO)\n```objc\n   \n-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{\n    NSString *url = self.dataArray[indexPath.row];\n    /**\n     *  参数1:图片URL\n     *  参数2:imageView 宽度\n     *  参数3:预估高度(此高度仅在图片尚未加载出来前起作用,不影响真实高度)\n     */\n    return [XHWebImageAutoSize imageHeightForURL:[NSURL URLWithString:url] layoutWidth:[UIScreen mainScreen].bounds.size.width-16 estimateHeight:200];\n}   \n\n-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{\n    DemoVC1Cell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];\n    if(!cell){\n        cell = [[DemoVC1Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];\n    }\n    NSString *url = self.dataArray[indexPath.row];\n    //加载网络图片使用SDWebImage\n    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:url] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {\n        /** 缓存image size */\n        [XHWebImageAutoSize storeImageSize:image forURL:imageURL completed:^(BOOL result) {\n            /** reload  */\n            if(result)  [tableView  xh_reloadDataForURL:imageURL];\n        }];\n    }];\n    return cell;\n}\n```\n##  API\n\n*   1.获取图片高度/尺寸及缓存相关\n\n```objc\n/**\n *   Get image height\n *\n *  @param url            imageURL\n *  @param layoutWidth    layoutWidth\n *  @param estimateHeight estimateHeight(default 100)\n *\n *  @return imageHeight\n */\n+(CGFloat)imageHeightForURL:(NSURL *)url layoutWidth:(CGFloat)layoutWidth estimateHeight:(CGFloat )estimateHeight;\n\n/**\n *  Get image width\n *\n *  @param url            imageURL\n *  @param layoutHeight   layoutHeight\n *  @param estimateWidth estimateWidth(default 90)\n *\n *  @return imageHeight\n */\n+(CGFloat)imageWidthForURL:(NSURL *)url layoutHeight:(CGFloat)layoutHeight estimateWidth:(CGFloat )estimateWidth;\n\n/**\n *  Get image size from cache,query the disk cache synchronously after checking the memory cache\n *\n *  @param url imageURL\n *\n *  @return imageSize\n */\n+(CGSize )imageSizeFromCacheForURL:(NSURL *)url;\n\n/**\n *  Store an imageSize into memory and disk cache\n *\n *  @param image          image\n *  @param url            imageURL\n *  @param completedBlock An block that should be executed after the imageSize has been saved (optional)\n */\n+(void)storeImageSize:(UIImage *)image forURL:(NSURL *)url completed:(XHWebImageAutoSizeCacheCompletionBlock)completedBlock;\n\n```\n\n*   2.tableView reload\n\n```objc\n\n/**\n Reload tableView\n\n @param url imageURL\n */\n-(void)xh_reloadDataForURL:(NSURL *)url;\n\n```\n\n*   3.collectionView reload\n\n```objc\n\n/**\n Reload collectionView\n \n @param url imageURL\n */\n-(void)xh_reloadDataForURL:(NSURL *)url;\n\n```\n##  安装\n### 1.手动添加:\u003cbr\u003e\n*   1.将 XHWebImageAutoSize 文件夹添加到工程目录中\u003cbr\u003e\n*   2.导入 XHWebImageAutoSize.h\n\n### 2.CocoaPods:\u003cbr\u003e\n*   1.在 Podfile 中添加 pod 'XHWebImageAutoSize'\u003cbr\u003e\n*   2.执行 pod install 或 pod update\u003cbr\u003e\n*   3.导入 XHWebImageAutoSize.h\n\n##  Tips\n*   1.如果发现pod search XHWebImageAutoSize 搜索出来的不是最新版本，需要在终端执行cd ~/desktop退回到desktop，然后执行pod setup命令更新本地spec缓存（需要几分钟），然后再搜索就可以了\n*   2.如果你发现你执行pod install后,导入的不是最新版本,请删除Podfile.lock文件,在执行一次 pod install\n*   3.如果在使用过程中遇到BUG，希望你能Issues我，谢谢（或者尝试下载最新的代码看看BUG修复没有）\n\n##  系统要求\n*   该项目最低支持 iOS 7.0 和 Xcode 7.0\n\n##  许可证\nXHWebImageAutoSize 使用 MIT 许可证，详情见 LICENSE 文件","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderzhuxh%2Fxhwebimageautosize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderzhuxh%2Fxhwebimageautosize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderzhuxh%2Fxhwebimageautosize/lists"}