{"id":17977967,"url":"https://github.com/coderyi/autolayoutdemo","last_synced_at":"2025-03-25T17:31:08.053Z","repository":{"id":33762700,"uuid":"37418264","full_name":"coderyi/AutoLayoutDemo","owner":"coderyi","description":"AutoLayout代码实现方式的基本使用，包括NSLayoutConstraint创建一个约束，VFL创建一组约束以及使用Autolayout实现UITableView的Cell动态布局和高度动态改变","archived":false,"fork":false,"pushed_at":"2019-09-17T06:58:47.000Z","size":794,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-20T13:32:44.794Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-14T15:42:41.000Z","updated_at":"2025-02-19T23:06:36.000Z","dependencies_parsed_at":"2022-09-10T18:21:50.795Z","dependency_job_id":null,"html_url":"https://github.com/coderyi/AutoLayoutDemo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2FAutoLayoutDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2FAutoLayoutDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2FAutoLayoutDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderyi%2FAutoLayoutDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderyi","download_url":"https://codeload.github.com/coderyi/AutoLayoutDemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245510623,"owners_count":20627231,"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-10-29T17:30:21.021Z","updated_at":"2025-03-25T17:31:07.669Z","avatar_url":"https://github.com/coderyi.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoLayoutDemo\nAutoLayout代码实现方式的基本使用，是不使用XIB的福音，包括NSLayoutConstraint创建一个约束，VFL（Visual format language　）创建一组约束以及使用Autolayout实现UITableView的Cell动态布局和高度动态改变\n\nAutoLayout其实是一种非常好的屏幕适配方案，包括不同分辨率的iPhone、横竖屏、iPhone与iPad，不学之前觉得他很鸡肋，学了之后发现它其实很好用。\n\n####NSLayoutConstraint创建一个约束\n参考链接：[   http://www.mgenware.com/blog/?p=490](   http://www.mgenware.com/blog/?p=490)\n\nConstraintViewController类是这个内容演示类，主要通过NSLayoutConstraint来约束两个不同View之间的关系。\n\n NSLayoutConstraint *constraint = [NSLayoutConstraint\n constraintWithItem:\n attribute:\n relatedBy:\n toItem:\n attribute:\n multiplier:\n constant:];\n \n 创建一个约束，参数说明:\n \n 第一个参数:指定约束左边的视图view1\n \n 第二个参数:指定view1的属性attr1，具体见上面的 NSLayoutAttribute。\n \n 第三个参数:指定左右两边的视图的关系relation，具体见上面的 NSLayoutRelation。\n \n 第四个参数:指定约束右边的视图view2\n \n 第五个参数:指定view2的属性attr2，具体见上面的 NSLayoutAttribute。\n \n 第六个参数:指定一个与view2属性相乘的乘数multiplier\n \n 第七个参数:指定一个与view2属性相加的浮点数constant\n \n\n这个函数的对照公式为: view1.attr1 = view2.attr2 * multiplier + constant\n\n如果你想设置的约束里不需要第二个view，要将第四个参数设为nil，第五个参数设为NSLayoutAttributeNotAnAttribute\n\n上面关于NSLayoutConstraint说明的参考链接：\n[http://rainbownight.blog.51cto.com/1336585/1316181](http://rainbownight.blog.51cto.com/1336585/1316181)\n\n\n\n####VFL创建一组约束\n参考链接：[ 使用Auto Layout中的VFL(Visual format language)——代码实现自动布局]( http://www.cnblogs.com/wupei/p/4150626.html)\n可以使用可视化格式化语言Visual Format Language来创建一组约束\n\n使用VFL创建一组约束，参数说明:\n\n 第一个参数：使用VFL格式化的字符串，具体语法参考下面的官方链接\n \n 第二个参数：指定VFL中所有对象的布局属性和方向。比如2个视图使用V布局，可以使用 NSLayoutFormatAlignAllLeft 让他们对齐\n \n 第三个参数：度量、指标的字典，字典里面的key可以写在第一个参数中。编译器解析时，自动替换为metrics字典中的value\n \n 第四个参数：指定约束的一个或多个视图\n \n NSArray *constrtArr = [NSLayoutConstraint\n constraintsWithVisualFormat:\n options:\n metrics:\n views:];\n\n可视化格式化语言Visual Format Language\n\n[Visual Format Language官方文档](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html#//apple_ref/doc/uid/TP40010853-CH3-SW1)\n\n\n 语法总结：\n \n 1、\"H\" 表示水平方向，\"V\" 表示垂直方向\n \n 2、\"|\" 表示superview的边界\n \n 3、\"[]\" 表示view，\"()\"表示尺寸数，可以多个条件组合，中间使用逗号分隔，如 view(\u003e=70,\u003c=100)\n \n 4、\"＠\" 表示优先级。如V:|-50@750-[view(55)]，或者写到metrics里面更好\n\n\n上面的说明参考链接：[https://github.com/jaywhj/AutoLayout](https://github.com/jaywhj/AutoLayout)\n\n\n####使用Autolayout实现UITableView的Cell动态布局和高度动态改变\n参考链接：[ IOS 6.0+ Autolayout — UITableViewCell 高度调整](http://my.oschina.net/carson6931/blog/363234)\n\n效果可以参考下图，\n\n\n![AutoLayoutDemo](http://7u2k5i.com1.z0.glb.clouddn.com/github_autolayoutdemo1.png?imageMogr2/thumbnail/!50p) \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderyi%2Fautolayoutdemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderyi%2Fautolayoutdemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderyi%2Fautolayoutdemo/lists"}