{"id":17928485,"url":"https://github.com/anthonylatsis/anchora","last_synced_at":"2025-08-10T11:05:06.032Z","repository":{"id":56901955,"uuid":"120834300","full_name":"AnthonyLatsis/Anchora","owner":"AnthonyLatsis","description":"A small framework that abstracts over UIKit's Auto Layout engine in a native style to tidy up your constraints.","archived":false,"fork":false,"pushed_at":"2019-07-25T12:25:23.000Z","size":356,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T02:33:39.204Z","etag":null,"topics":["autolayout","constraints","ios","swift","uikit","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/AnthonyLatsis.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":"2018-02-09T00:15:11.000Z","updated_at":"2023-07-28T06:57:24.000Z","dependencies_parsed_at":"2022-08-20T18:50:39.452Z","dependency_job_id":null,"html_url":"https://github.com/AnthonyLatsis/Anchora","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnthonyLatsis%2FAnchora","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnthonyLatsis%2FAnchora/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnthonyLatsis%2FAnchora/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnthonyLatsis%2FAnchora/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnthonyLatsis","download_url":"https://codeload.github.com/AnthonyLatsis/Anchora/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246981151,"owners_count":20863825,"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":["autolayout","constraints","ios","swift","uikit","xcode"],"created_at":"2024-10-28T21:03:24.746Z","updated_at":"2025-04-03T09:43:51.334Z","avatar_url":"https://github.com/AnthonyLatsis.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anchora\nA small framework that abstracts over UIKit's Auto Layout engine in a native style to tidy up your constraints.\n\n## Usage\n\nEach constraint is a linear equation with the following format:\n```\nitem1.attribute1 = multiplier * item2.attribute2 + constant\n```\n\nAnchora makes use of this equation to provide a convenient and intuitive way of building constraints in a native style.\n\nSingle constraints are constructed using the following methods: `equals(_:)`, `lessOrEquals(_:)`, `greaterOrEquals(_:)`, \neach of which represents a layout relation and takes a single expression of the following format, where `multiplier` and `constant` are optional:\n```\nanchor [* or /] multiplier [+ or -] constant\n```\n\nFor instance,\n\n``` swift\nview1.centerXAnchor.equals(view2.centerXAnchor * 2 + 10)\n\nview1.rightAnchor.lessOrEquals(view2.leftAnchor - 8)\n\nview1.heightAnchor.equals(view2.heightAnchor)\n```\n\nAs an exception, `NSLayoutDimension` constraints can simply take a number.\n``` swift\nview.widthAnchor.equals(80)\n```\n\n### Anchor Groups\n\nApart from the existing anchors we all know, Anchora comes with some built-in anchor groups that serve a great means\nof brevity when constructing several related constraints at once. The order in the list of anchors a group represents matters!\n\n* `centerAnchors` == (`centerXAnchor`, `centerYAnchor`)\n* `sizeAnchors` == (`widthAnchor`, `heightAnchor`)\n* `edgeAnchors` == (`topAnchor`, `leftAnchor`, `bottomAnchor`, `rightAnchor`)\n\n\nThe `constrain(...)` method allows to create constraints by associating a set of individual anchors to their equivalents\nin the anchor group, while `equal(_:)` is the bulk variant of `equals(_:)` for an individual anchor.\n\n```swift \nview1.edgeAnchors.equal(view2.edgeAnchors)\n\n// Equivalent to\nview1.topAnchor.equals(view2.topAnchor)\nview1.leftAnchor.equals(view2.leftAnchor)\nview1.bottomAnchor.equals(view2.bottomAnchor)\nview1.rightAnchor.equals(view2.rightAnchor)\n```\n```swift\nview1.sizeAnchors.equal(100)\n\n// Equivalent to\nview1.widthAnchor.equals(100)\nview1.heightAnchor.equals(100)\n```\n```swift\nview1.centerAnchors.constrain(view2.centerXAnchor - 10, view2.centerYAnchor) \n\n// Equivalent to\nview1.centerXAnchor.equals(view2.centerXAnchor - 10)\nview1.centerYAnchor.equals(view2.centerYAnchor)\n```\n___\n\nFor convenience, Anchora methods return discardable active constraints. If you need an inactive constraint, use `inactive()`.\n``` swift\nlet constraint = view1.rightAnchor.equals(view2.leftAnchor - 8).inactive()\n```\n\n## Requirements\n\n* Xcode 9 +\n* Swift 4 +\n* iOS 10 +\n\n## Installation\n\nYou can integrate Anchora with [CocoaPods](https://cocoapods.org/). Add it to your `Podfile` and run `$ pod install`.\n\n``` ruby\nplatform :ios, '10.0'\nuse_frameworks!\n\ntarget '\u003cYour Target\u003e' do\n    pod 'Anchora'\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonylatsis%2Fanchora","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthonylatsis%2Fanchora","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonylatsis%2Fanchora/lists"}