{"id":32146914,"url":"https://github.com/neilsultimatelab/autolayoutextension","last_synced_at":"2026-02-19T02:02:14.904Z","repository":{"id":58930898,"uuid":"529814262","full_name":"NeilsUltimateLab/AutolayoutExtension","owner":"NeilsUltimateLab","description":null,"archived":false,"fork":false,"pushed_at":"2022-09-09T10:55:32.000Z","size":22,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-15T13:48:41.879Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/NeilsUltimateLab.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":"2022-08-28T09:16:44.000Z","updated_at":"2024-03-18T14:59:40.000Z","dependencies_parsed_at":"2022-09-09T16:51:47.557Z","dependency_job_id":null,"html_url":"https://github.com/NeilsUltimateLab/AutolayoutExtension","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/NeilsUltimateLab/AutolayoutExtension","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeilsUltimateLab%2FAutolayoutExtension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeilsUltimateLab%2FAutolayoutExtension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeilsUltimateLab%2FAutolayoutExtension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeilsUltimateLab%2FAutolayoutExtension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NeilsUltimateLab","download_url":"https://codeload.github.com/NeilsUltimateLab/AutolayoutExtension/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeilsUltimateLab%2FAutolayoutExtension/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29600845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T00:59:38.239Z","status":"online","status_checked_at":"2026-02-19T02:00:07.702Z","response_time":117,"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":"2025-10-21T08:32:55.652Z","updated_at":"2026-02-19T02:02:14.899Z","avatar_url":"https://github.com/NeilsUltimateLab.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutolayoutExtension\n\nA light weight, clutter-free, declarative syntax to Autolayout. (⚠️ Requires Swift 5.7)\n\n## Overview\n\nWe all use Autolayout to arrange and position UI components in UIKit. And doing in code is quite an exercise to brain to imagine how this piece of code will take reflect on screen.\n\nWe need to think about buttons, labels, various controls, child views. All UI componenets and their relation in between, parent, child, siblings, safe area, layout guides, size classes 🤯.\n\nLet's try to make this little simpler with some inspiration from **SwiftUI** and a lesser known friend Swift `KeyPaths`.\n\n## The Point\nWe all have written code like this.\n\n```swift\nself.view.addSubview(otherView)\notherView.translatesAutoresizingMaskIntoConstraints = true\n\notherView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true\notherView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -16).isActive = true\n...\n```\n\nIn above code, just to add the `leadingAnchor` to `otherView` with respect to `view` the whole line is very lengthy and wordy.\n\n```swift\notherView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true\n```\n\nWhat if we just write the same line using.\n```swift\nself.view.anchor(otherView) {\n    EqualTo(\\.leadingAnchor)\n    EqualTo(\\.trailingAnchor).constant(-16)\n}\n```\nMuch more clear, concise and readable at a glance.\n\n## Map\n\n| Native | AutolayoutExtension | Anchor Type | \n| :---- | :----------------- | :---------- |\n| `.constraint(equalTo:)` | ``EqualTo`` | `NSLayoutAnchor\u003cAxis\u003e` |\n| `.constraint(equalTo:constant)` | ``EqualToConstant`` | `NSLayoutDimension` |\n| `.constraint(greaterThanOrEqualTo:)` | ``GreaterThanOrEqualTo`` | `NSLayoutAnchor\u003cAxis\u003e` |\n| `.constraint(greaterThanOrEqualTo:constant)` | ``GreaterThanOrEqualToConstant`` | `NSLayoutDimension` | \n| `.constraint(lessThanOrEqualTo:)` | ``LessThanOrEqualTo`` |`NSLayoutAnchor\u003cAxis\u003e` |\n| `.constraint(lessThanOrEqualTo:Constant)` | ``LessThanOrEqualToConstant`` | `NSLayoutDimension` |\n\n## Modifiers\nThere 3 in-built constraint modifiers available. \n\n1. `.constant(_ constant: CGFloat)`\n2. `.priority(_ priority : UILayoutPriority)`\n3. `.id\u003cID: Hashable\u003e(_ id: ID)`\n\n## Example\n\n```swift\nimport AutolayoutExtension\nimport UIKit\n\nclass AView: UIView {\n    var condition: Bool = false {\n        didSet {\n            self.updateLayout()\n        }\n    }\n    \n    private var labelTopConstraint: NSLayoutConstraint?\n    private var imageBottomConstraint: NSLayoutConstraint?\n    \n    private lazy var titleLabel: UILabel = {\n        let label = UILabel()\n        return label\n    }()\n    \n    private lazy var imageView: UIImageView = {\n        let imageView = UIImageView()\n        return imageView\n    }()\n    \n    override init(frame: CGRect) {\n        super.init(frame: frame)\n        configureSubviews()\n    }\n    \n    required init?(coder: NSCoder) {\n        super.init(coder: coder)\n        configureSubviews()\n    }\n    \n    private func configureSubviews() {\n        self.addSubview(titleLabel)\n        self.addSubview(imageView)\n        \n        let topAnchorID = UUID()\n        let bottomAnchorID = UUID()\n        \n        let labelConstraints = self.constraint(titleLabel) {\n            EqualTo(\\.leadingAnchor)\n            EqualTo(\\.trailingAnchor)\n            EqualTo(\\.topAnchor)\n                .constant(24)\n                .id(topAnchorID)\n            EqualToConstant(\\.heightAnchor, constant: 32)\n        }\n        \n        let imageConstraints = self.constraint(imageView) {\n            EqualTo(\\.centerXAnchor)\n            GreaterThanOrEqualTo(\\.leadingAnchor)\n                .constant(12)\n            EqualTo(\\.topAnchor, with: titleLabel.bottomAnchor)\n                .constant(12)\n            EqualTo(\\.bottomAnchor)\n                .priority(.defaultHigh)\n                .id(bottomAnchorID)\n        }\n        \n        self.labelTopConstraint = labelConstraints[topAnchorID]\n        self.imageBottomConstraint = imageConstraints[bottomAnchorID]\n    }\n    \n    private func updateLayout() {\n        self.labelTopConstraint?.constant = condition ? 24 : 32\n        self.imageBottomConstraint?.constant = condition ? 24 : 0\n        self.layoutIfNeeded()\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneilsultimatelab%2Fautolayoutextension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneilsultimatelab%2Fautolayoutextension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneilsultimatelab%2Fautolayoutextension/lists"}