{"id":19847035,"url":"https://github.com/polidea/plvisualattributeconstraints","last_synced_at":"2025-10-04T14:11:39.201Z","repository":{"id":9564645,"uuid":"11475820","full_name":"Polidea/PLVisualAttributeConstraints","owner":"Polidea","description":"Custom VFL (Visual Format Language) for creating NSLayoutConstraint's. Offers more readable and concise replacement for constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant: (NSLayoutConstraint, AutoLayout mechanism)","archived":false,"fork":false,"pushed_at":"2016-08-03T14:16:21.000Z","size":287,"stargazers_count":22,"open_issues_count":1,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-09-14T21:43:06.128Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Polidea.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":"2013-07-17T12:46:27.000Z","updated_at":"2021-11-16T13:57:58.000Z","dependencies_parsed_at":"2022-09-24T04:02:13.655Z","dependency_job_id":null,"html_url":"https://github.com/Polidea/PLVisualAttributeConstraints","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Polidea/PLVisualAttributeConstraints","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polidea%2FPLVisualAttributeConstraints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polidea%2FPLVisualAttributeConstraints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polidea%2FPLVisualAttributeConstraints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polidea%2FPLVisualAttributeConstraints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Polidea","download_url":"https://codeload.github.com/Polidea/PLVisualAttributeConstraints/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polidea%2FPLVisualAttributeConstraints/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278322146,"owners_count":25967874,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-12T13:13:15.926Z","updated_at":"2025-10-04T14:11:39.170Z","avatar_url":"https://github.com/Polidea.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\n\nThis library is deprecated in favor of [PLXVisualAttributeConstraints](https://github.com/Polidea/PLXVisualAttributeConstraints)\n\n---\n\n## Description\n\n**PLVisualAttributeConstraints** is small lib that makes it easier to create layout constraints (see: [NSLayoutConstraint](http://developer.apple.com/library/ios/#documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html) class).\n\nIf you don't know much about the **AutoLayout** mechanism, I strongly suggest you to go [there](https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AutolayoutPG/Articles/Introduction.html) for more information.\n\nPLVisualAttributeConstraints **does not** try to replace standard [VFL (Visual Format Language)](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/AutolayoutPG/Articles/formatLanguage.html) or alter default Apple's mechanisms. It integrates with it seamlessly and greatly improves developer's productivity and code readability.\n\n## Example\n\nIn a nutshell, having two views...\n```objective-c\n  UIView *firstViewObj = ...\n  UIView *secondViewObj = ...\n```\n\nusing this lib you can create layout constraint like...\n```objective-c\n  NSDictionary *views = @{\n          @\"firstView\" : firstViewObj,\n          @\"secondView\" : secondViewObj\n  };\n\n  NSLayoutConstraint *constraint1 = \n    [NSLayoutConstraint attributeConstraintWithVisualFormat:@\"secondView.left \u003e= firstView.left * 2 + 10\"\n                                                                                      views:views];\n```\n\ninstead of standard\n```objective-c\n  NSLayoutConstraint *constraint2 = \n    [NSLayoutConstraint constraintWithItem:secondViewObj\n                                 attribute:NSLayoutAttributeLeft\n                                 relatedBy:NSLayoutRelationGreaterThanOrEqual\n                                    toItem:firstViewObj\n                                 attribute:NSLayoutAttributeLeft\n                                multiplier:2\n                                  constant:10];\n```\n\nThose two constraints (`constraint1` and `constraint2`) are **identical** to each other.\n\nIt's very likely that you'll have lots of constraints (it's usual case). \nNote, that you need to create dictionary with views only *once* (f.e. at the very beggining of a constraints-creating method) and then you go on creating them with similar one-liners (like in the example above) or you can take advantage of another method:\n\n```objective-c\n  NSArray *constraints = [NSLayoutConstraint attributeConstraintsWithVisualFormatsArray:@[\n          @\"secondView.left \u003c= firstView.left - 10\",\n          @\"secondView.right \u003e= firstView.right + 10\",\n          @\"secondView.top == firstView.bottom * 2.5 + 5\",\n  ]                                                                               views:views];\n\n```\n\n## Grammar by example ;)\n\n### Valid grammar examples\nInstead of introducing formal grammar here, I'm quite convinced that a few examples will be more that enough to get you up and running.\n\n``control1.top \u003e= control2.bottom + 20``\n``control1.top \u003c= control2.bottom - 20.5``\n``control1.top == control2.bottom * 2.3 + 4.5``\n``control1.top \u003e= control2.bottom * 2 - 10``\n\nA little bit hacky (read on to see why):\n``control1.top \u003e= 100``\n``control1.top == 100.5``\n\n###Supported attributes are:\n`top`, `bottom`, `left`, `right`, `leading`, `trailing`, `width`, `height`, `centerx`, `centery`, `baseline` (case insensitive)\nThose attributes are mapped one-to-one with [those enums](http://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html#//apple_ref/doc/c_ref/NSLayoutAttribute).\n\n###Supported relations:\n``==``, ``\u003e=``, ``\u003c=`` (mapped one-to-one with [those enums](http://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html#//apple_ref/doc/c_ref/NSLayoutRelation))\n\n## Demo\n\nTo see the lib in action (and in comparision with [standard constraint-creating method](http://developer.apple.com/library/ios/#documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:)), checkout the project. Open it via `*.xcworkspace` and **not** `*.xcproject` file (why? [CocoaPods](https://github.com/CocoaPods/CocoaPods)). Yeap, I know that this example is somewhat artificial :) But it'll do. If you have better suggestions on how to prepare the demo, pull requests are welcome :)\n\n## Hacks\n\nAs I've mentioned above, formats like ``control1.top \u003e= 100`` (without an attribute on the right side, only constant) are supported.\n\nWhole lib is a thin wrapper above [this method](http://developer.apple.com/library/ios/#documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:) and as we read:\n\n\u003e Constraints are of the form `view1.attr1 \u003crelation\u003e view2.attr2 * multiplier + constant`. \n\u003e If the constraint you wish to express does not have a second view and attribute, use `nil` and `NSLayoutAttributeNotAnAttribute`.\n\nWell... That works for constraints with `width` or `height` attribute on the left side (``control1.width == 100``). \nIn case of any other attribute (`top`, `left`...) it throws an exception upon constraint creation... And it somewhat makes sense. \n\nSometimes you want to create such a constraint anyway. In that case, you can create `control1.top == control1.top * 0 + 50` which should behave exactly the same as `control1.top == 50` and it does :)\n\n**TL;DR**\n\nConstraints like ``control1.top \u003e= 100`` are automagically created as ``control1.top \u003e= control1.top * 0 + 100``, which I consider a bit hacky, therefore elaborate on it here.\n\n\n## Installation\n\nJust copy source files under `PLVisualAttributeConstraints/PLVisualAttributeConstraints/*` into your project.\nSupport for installation via [CocoaPods](https://github.com/CocoaPods/CocoaPods) will follow shortly.\n\n## Requirements\n* iOS 6.0+\n\n## Notes:\n* to open project, use `*.xcworkspace` and **not** `*.xcproject` file (as I use, love and recommend [CocoaPods](https://github.com/CocoaPods/CocoaPods))\n* tests are created using [Kiwi framework](https://github.com/allending/Kiwi)\n\n## Author\nKamil Jaworski (kamil.jaworski@gmail.com), [Polidea](http://www.polidea.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolidea%2Fplvisualattributeconstraints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolidea%2Fplvisualattributeconstraints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolidea%2Fplvisualattributeconstraints/lists"}