{"id":13696110,"url":"https://github.com/gsdios/SDAutoLayout","last_synced_at":"2025-05-03T14:31:00.677Z","repository":{"id":41366149,"uuid":"44443578","full_name":"gsdios/SDAutoLayout","owner":"gsdios","description":"One line of code to implement automatic layout.  一行代码搞定自动布局！支持Cell和Tableview高度自适应，Label和ScrollView内容自适应，致力于做最简单易用的AutoLayout库。The most easy way for autoLayout. Based on runtime.","archived":false,"fork":false,"pushed_at":"2023-05-12T15:20:35.000Z","size":15585,"stargazers_count":5900,"open_issues_count":165,"forks_count":1274,"subscribers_count":227,"default_branch":"master","last_synced_at":"2025-04-10T19:51:35.216Z","etag":null,"topics":[],"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/gsdios.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,"governance":null}},"created_at":"2015-10-17T15:50:14.000Z","updated_at":"2025-04-09T10:35:47.000Z","dependencies_parsed_at":"2022-08-25T11:40:51.069Z","dependency_job_id":"8aff1979-72ff-432d-9948-b4d30b520093","html_url":"https://github.com/gsdios/SDAutoLayout","commit_stats":{"total_commits":325,"total_committers":4,"mean_commits":81.25,"dds":0.08615384615384614,"last_synced_commit":"a5e7527267ef50337ace81f041f570bb56b6209f"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gsdios%2FSDAutoLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gsdios%2FSDAutoLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gsdios%2FSDAutoLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gsdios%2FSDAutoLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gsdios","download_url":"https://codeload.github.com/gsdios/SDAutoLayout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252203160,"owners_count":21710899,"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":[],"created_at":"2024-08-02T18:00:36.343Z","updated_at":"2025-05-03T14:30:55.669Z","avatar_url":"https://github.com/gsdios.png","language":"Objective-C","funding_links":[],"categories":["UI Frameworks","Objective-C  Stars 1000以内排名整理","iOS"],"sub_categories":["ListView"],"readme":"# SDAutoLayout（一行代码搞定自动布局！）\n\n一行代码搞定自动布局！致力于做最简单易用的Autolayout库。The most easy way for autolayout.\n\n### 字节跳动 iOS 岗位招聘\n北上广深杭大量招人，各种研发岗位都在找，有意向者可以直接点击后面链接投递简历或者联系我 gsdios@126.com https://job.toutiao.com/s/eL91QMm，\n\n## 众多公司和个人开发者已经使用本库布局：\nSDAutoLayout使用者开发的部分app截图 http://www.jianshu.com/p/9bc04d3effb8\n\n## 技术支持(QQ交流群)：\n\n497140713（1群）  519489682（2群已满）\n\n## Pod支持：\n\n支持pod：  pod 'SDAutoLayout', '~\u003e 2.1.3'\n\n## 更新记录：\n2018.11.28 -- 修复部分开发者违规调用load的super方法导致自动布局失效的问题\n\n2018.07.02 -- 修复了部分布局组合下view居中布局失效bug\n\n2017.11.11 -- 实现控制富文本可显示行数功能\n\n2017.11.11 -- 解决朋友圈demo在iOS11上文字收折或者展开时出现cell跳动问题\n\n2017.06.26 -- 解决部分开发者反应因出现“UITableViewCellContentView”而导致应用审核被拒问题\n\n2016.08.12 -- 实现在tableview插入新的cell数据时自动缓存管理\n\n2016.06.30 -- 增加多参照view的leftSpaceToView和topSpaceToView约束，例：topSpaceToView(@[self.view3, self.view4], 30)\n\n2016.06.24 -- 修复给button设置约束时在iOS8.x系统中出现的崩溃问题；发布2.1.2版本\n\n2016.06.23 -- 实现删除某行cell时自动调整height缓存\n\n2016.05.16 -- 修复用xib生成的view出现的部分约束失效问题（发布pod2.0.0版本）\n\n2016.05.15 -- 增加设置偏移量offset功能\n\n2016.04.30 -- 修复之前button作为父视图时内部控件不能自动布局问题\n\n2016.04.05 -- 修复宽度自适应label在重用时候偶尔出现的宽度计算不准确的问题（发布pod1.51版本）\n\n2016.03.23 -- 升级了缓存机制，新版本在tableview滑动cell时候流畅度和性能提升20%以上（发布pod1.50版本）\n\n2016.01.23 -- 增加label对attributedString的内容自适应\n\n2016.01.21 -- 实现tableview局部刷新cell高度缓存的自动管理\n\n2016.01.20 -- demo适配在ios7上的屏幕旋转问题\n\n2016.01.18 -- 推出“普通简化版”tableview的cell自动高度方法（推荐使用），原来的需2步设置的普通版方法将标记过期\n\n2016.01.13 -- 增加在不确定bottom view的情况下的cell高度自适应方法\n\n2016.01.07 -- 1.增加 scrollview 横向内容自适应功能；2.增加view宽高相等的功能\n\n2016.01.03 -- 增加任何类型对象都可以实现一行代码搞定cell高度自适应；增加文档注释\n\n2015.12.08 -- 重大升级：1.支持scrollview内容自适应；2.任意添加或者修改约束不冲突；3.性能提升40%以上；4.添加最大、最小宽高约束\n\n\n## 视频教程：\n☆☆ SDAutoLayout 基础版视频教程：http://www.letv.com/ptv/vplay/24038772.html ☆☆\n\n☆☆ SDAutoLayout 进阶版视频教程：http://www.letv.com/ptv/vplay/24381390.html ☆☆\n\n☆☆ SDAutoLayout 原理简介视频教程：http://www.iqiyi.com/w_19rt0tec4p.html ☆☆\n\n☆☆ SDAutoLayout 朋友圈demo视频教程：http://v.youku.com/v_show/id_XMTYzNzg2NzA0MA==.html ☆☆\n\n## 部分SDAutoLayout的DEMO：\n\n完整微信Demo https://github.com/gsdios/GSD_WeiXin\n\n![](http://ww3.sinaimg.cn/mw690/9b8146edgw1f1nm3pziawg205u0a0qv5.gif)![](http://ww1.sinaimg.cn/bmiddle/9b8146edgw1f06aoe2umhg206e0b4u0x.gif)![](http://ww4.sinaimg.cn/bmiddle/9b8146edgw1ezal3smihcg206y0ciqv5.gif)![](http://ww3.sinaimg.cn/mw690/9b8146edgw1f1nm3lweg3g207s0dcu0x.gif)![](http://ww2.sinaimg.cn/mw690/9b8146edgw1f23irukb0qg207i0dwu0x.gif)![](http://ww2.sinaimg.cn/bmiddle/9b8146edgw1eya1jv951ig208c0etqv5.gif)\n\n\n\n#   用法简介\n    \n    \n## 普通view的自动布局：\n\n#### 用法示例\n     用法一\n```\n    _view.sd_layout\n    .leftSpaceToView(self.view, 10)\n    .topSpaceToView(self.view, 80)\n    .heightIs(130)\n    .widthRatioToView(self.view, 0.4);  \n```\n    用法二 （一行代码搞定，其实用法一也是一行代码）\n```\n    _view.sd_layout.leftSpaceToView(self.view, 10).topSpaceToView(self.view,80).heightIs(130).widthRatioToView(self.view, 0.4);\n```\n    综合示例\n```   \n    \n    *******************************************************************************\n        \n        注意:先把需要自动布局的view加入父view然后在进行自动布局，例： \n\n        UIView *view0 = [UIView new];\n        UIView *view1 = [UIView new];\n        [self.view addSubview:view0];\n        [self.view addSubview:view1];\n        \n        view0.sd_layout\n        .leftSpaceToView(self.view, 10)\n        .topSpaceToView(self.view, 80)\n        .heightIs(100)\n        .widthRatioToView(self.view, 0.4);\n        \n        view1.sd_layout\n        .leftSpaceToView(view0, 10)\n        .topEqualToView(view0)\n        .heightRatioToView(view0, 1)\n        .rightSpaceToView(self.view, 10);\n\n    *******************************************************************************\n```  \n\n## UILabel文字自适应\n```\n// autoHeightRatio() 传0则根据文字自动计算高度（传大于0的值则根据此数值设置高度和宽度的比值）\n    _label.sd_layout.autoHeightRatio(0);\n```\n    \n## tableview和cell高度自适应：   \n\n#### 普通（简化）版【推荐使用】：tableview 高度自适应设置只需要2步\n```    \n    1. \u003e\u003e 设置cell高度自适应：\n    // cell布局设置好之后调用此方法就可以实现高度自适应（注意：如果用高度自适应则不要再以cell的底边为参照去布局其子view）\n\n    [cell setupAutoHeightWithBottomView:_view4 bottomMargin:10];\n```\n```   \n    2. \u003e\u003e 获取自动计算出的cell高度\n\n    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath\n    {\n        id model = self.modelsArray[indexPath.row];\n        // 获取cell高度\n        return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@\"model\" cellClass:[DemoVC9Cell class]  contentViewWidth:cellContentViewWith];\n    }\n```\n\n#### 升级版（适应于cell条数少于100的tableview）：tableview 高度自适应设置只需要2步\n```    \n    1. \u003e\u003e 设置cell高度自适应：\n    // cell布局设置好之后调用此方法就可以实现高度自适应（注意：如果用高度自适应则不要再以cell的底边为参照去布局其子view）\n\n    [cell setupAutoHeightWithBottomView:_view4 bottomMargin:10];\n```\n```    \n    2. \u003e\u003e 获取自动计算出的cell高度 \n\n    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath\n    {\n    // 获取cell高度\n    return [self cellHeightForIndexPath:indexPath cellContentViewWidth:[UIScreen mainScreen].bounds.size.width];\n    }\n```\n    \n\n#### 自动布局用法简析\n\n![](http://ww1.sinaimg.cn/mw690/9b8146edgw1ex4or5ixkjj20k60gw3zg.jpg)\n\n```\n   1.1 \u003e leftSpaceToView(self.view, 10)\n   \n   方法名中带有“SpaceToView”的方法表示到某个参照view的间距，需要传递2个参数：（UIView）参照view 和 （CGFloat）间距数值\n\n   1.2 \u003e widthRatioToView(self.view, 1)\n   \n   方法名中带有“RatioToView”的方法表示view的宽度或者高度等属性相对于参照view的对应属性值的比例，需要传递2个参数：（UIView）参照view 和 （CGFloat）倍数\n \n   1.3 \u003e topEqualToView(view)\n   \n   方法名中带有“EqualToView”的方法表示view的某一属性等于参照view的对应的属性值，需要传递1个参数：（UIView）参照view\n   \n   1.4 \u003e widthIs(100)\n   \n   方法名中带有“Is”的方法表示view的某一属性值等于参数数值，需要传递1个参数：（CGFloat）数值\n```\n\n# PS\n\n// 如果需要用“断言”调试程序请打开此宏(位于UIView+SDAutoLayout.h)\n\n//#define SDDebugWithAssert\n\n\n![](http://ww3.sinaimg.cn/bmiddle/9b8146edgw1ex4mukixr6g209g07lhdt.gif)\n\n\n![](http://upload-images.jianshu.io/upload_images/1157161-07fa43e0f539ebad.jpeg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n![](http://upload-images.jianshu.io/upload_images/1157161-453a5d33d7f3d48d.jpeg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgsdios%2FSDAutoLayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgsdios%2FSDAutoLayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgsdios%2FSDAutoLayout/lists"}