{"id":15561321,"url":"https://github.com/alexliubj/ezanchor","last_synced_at":"2025-04-23T22:29:37.026Z","repository":{"id":56909695,"uuid":"170376020","full_name":"alexliubj/EZAnchor","owner":"alexliubj","description":"An easier and faster way to code Autolayout","archived":false,"fork":false,"pushed_at":"2019-05-20T15:05:51.000Z","size":571,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T14:38:19.059Z","etag":null,"topics":["anchors","autolayout","center","constraint","constraints","ios","layout","library","nslayoutconstraint","sugar","superview","swift","swift4"],"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/alexliubj.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":"2019-02-12T19:13:47.000Z","updated_at":"2023-07-05T12:54:30.000Z","dependencies_parsed_at":"2022-08-21T04:20:29.669Z","dependency_job_id":null,"html_url":"https://github.com/alexliubj/EZAnchor","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexliubj%2FEZAnchor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexliubj%2FEZAnchor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexliubj%2FEZAnchor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexliubj%2FEZAnchor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexliubj","download_url":"https://codeload.github.com/alexliubj/EZAnchor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250526048,"owners_count":21445122,"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":["anchors","autolayout","center","constraint","constraints","ios","layout","library","nslayoutconstraint","sugar","superview","swift","swift4"],"created_at":"2024-10-02T16:07:25.961Z","updated_at":"2025-04-23T22:29:37.008Z","avatar_url":"https://github.com/alexliubj.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EZAnchor  [中文介绍](https://github.com/alexliubj/EZAnchor/blob/master/🇨🇳.md)\nAn easier way to code Autolayout\n\n![Image of EZAnchor](https://raw.githubusercontent.com/alexliubj/EZAnchor/master/Logo.png)\n\n[![Language: Swift 4](https://img.shields.io/badge/language-swift%204-f48041.svg?style=flat)](https://developer.apple.com/swift)\n![Platform: iOS 9+](https://img.shields.io/badge/platform-iOS-green.svg?style=flat)\n[![CocoaPods compatible](https://img.shields.io/badge/Cocoapods-compatible-4BC51D.svg?style=flat)](https://cocoapods.org/pods/SteviaLayout)\n![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)\n\n- [x] Are you annoyed of coding `.active = true` while using Autolayout Anchors over and over again?\n- [x] Are you annoyed of coding such long constraint sentence `refreshView.heightAnchor.constraint(equalToConstant: self.refreshViewHeight).isActive = true` over and over again?\n\nNow `EZAnchor` is definitely going to shorten your time of writing Autolayout Anchors by a simple installation.\nLet's see how it works:\n\n* Anchor constraint to another anchor\n```swift\n//Traditional way\nviewA.leadingAnchor.constraint(equalTo: viewB.leadingAnchor).isActive = true\n\n//With EZAnchor\nviewA.leading == viewB.leading\n```\n        \n* Anchor constraint to another anchor with constant\n```swift\n//Traditional way\nviewA.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 10).isActive = true\n\n//With EZAnchor\nviewA.leading == self.view.leading + 10\n```\n        \n* Anchor constraint to another anchor with negative constant\n```swift\n//Traditional way\nviewA.leadingAnchor.constraint(equalTo: viewB.leadingAnchor, constant: -10).isActive = true\n\n//With EZAnchor\nviewA.leading == viewB.leading - 10\n```\n        \n* Anchor lessThanOrEqualTo another anchor\n```swift\n//Traditional way\nviewA.leadingAnchor.constraint(lessThanOrEqualTo: viewB.leadingAnchor).isActive = true\n\n//With EZAnchor\nviewA.leading \u003c= viewB.leading\n```\n        \n* Anchor greaterThanOrEqualTo another anchor\n```swift\nviewA.leadingAnchor.constraint(greaterThanOrEqualTo: viewB.leadingAnchor).isActive = true\n\n//With EZAnchor\nviewA.leading \u003e= viewB.leading\n```\n        \n* Anchor lessThanOrEqualTo another anchor with constant\n```swift\nviewA.leadingAnchor.constraint(lessThanOrEqualTo: viewB.leadingAnchor, constant: 10).isActive = true\n\n//With EZAnchor\nviewA.leading \u003c= viewB.leading + 10\n```\n        \n* Anchor greaterThanOrEqualTo another anchor with constant\n```swift\n//Traditional way\nviewA.leadingAnchor.constraint(greaterThanOrEqualTo: viewB.leadingAnchor, constant: 10).isActive = true\n\n//With EZAnchor\nviewA.leading \u003e= viewB.leading - 10\n```\n        \n* Anchor equalTo another anchor with constant and multiplier\n```swift\n//Traditional way\nviewA.heightAnchor.constraint(equalTo: viewB.heightAnchor, multiplier: 0.1, constant: -10).isActive = true\n\n//With EZAnchor\nviewA.height == viewB.height * 0.1 - 10\n```\n\n* Work with Priority\n```swift\n//With EZAnchor\nviewA.leading == (viewB.leading + 0.1) ^ .defaultLow\n```\n\n## Installation\n\n### Drag and drop\nDirectly drag `EZAnchor` and drop into your Xcode project.\n\n### CocoaPods\nTo integrate EZAnchor into your Xcode project using CocoaPods, specify it in your Podfile:\n```\ntarget 'MyApp' do\n  pod 'EZAnchor'\nend\n```\n\n### Carthage\nTo integrate EZAnchor into your Xcode project using Carthage, specify it in your Cartfile:\n`coming soon`\n\nRun carthage update to build the framework and drag the built EZAnchor.framework into your Xcode project.\n\n## Demo\n\nYou can easily implement the following layout with very simple and clean code:\n```swift\n//set viewA's layout constraints\nlet viewA = UIView()\nviewA.backgroundColor = UIColor.red\nview.addEZSubview(viewA)\n        \nviewA.leading == view.leading + 5\nviewA.trailing == view.trailing - 5\nviewA.top == view.top + 15\nviewA.centerX == view.centerX\nviewA.height == view.height/2\n        \n//set viewB's layout constraints\nlet viewB = UIView()\nviewB.backgroundColor = UIColor.yellow\nview.addEZSubview(viewB)\n        \nviewB.top == viewA.bottom + 5\nviewB.leading == viewA.leading\nviewB.bottom == view.bottom - 5\nviewB.trailing == view.centerX - 5\n\n//set viewC's layout constraints        \nlet viewC = UIView()\nviewC.backgroundColor = UIColor.green\nview.addEZSubview(viewC)\n        \nviewC.top == viewB.top\nviewC.bottom == viewB.bottom\nviewC.leading == view.centerX + 5\nviewC.trailing == viewA.trailing\n        \n```\n![Image of DemoScreenshot](https://raw.githubusercontent.com/alexliubj/EZAnchor/master/demo.png)\n\n## Chaining function\n\n### Chaining way to code Autolayout with EZAnchor\n\n```swift\n\nviewA.setLeading(view.leading + 5)\n     .setTrailing(view.trailing - 5)\n     .setTop(view.top + 15)\n     .setCenterX(view.centerX)\n     .setHeight(view.height/2)\n\n\nviewB.setTop(viewA.bottom + 5)\n     .setLeading(viewA.leading)\n     .setBottom(view.bottom - 5)\n     .setTrailing(view.centerX - 5)\n\nviewC.setTop(viewB.top)\n     .setBottom(viewB.bottom)\n     .setLeading(view.centerX + 5)\n     .setTrailing(viewA.trailing)\n\n```\n\n## Limitations\n\n1. Better to have some basic concept of anchors, familiar with coding anchors programmatically. If not please learn from this link : [Programmatically Creating Constraints!](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html)\n\n2. Avoid defining custom `UIControl` or view has same name with `height` or `width`, there may have conflict with `EZAnchor` library\n\n## Others\n##### [WTF Autolayout](https://www.wtfautolayout.com) will help you debug autolayout complaints.\n##### Logo is generated with [Shopify logo maker](https://hatchful.shopify.com/)\n##### Inspired by: [PureLayout](https://github.com/PureLayout/PureLayout) [Stevia](https://github.com/freshOS/Stevia) [layout](https://github.com/nicklockwood/layout) \n\n## Todo\n- [ ] Unit tests\n- [ ] UI Tests\n- [ ] CI\n- [ ] Fastlane\n\n## License\n\nThis code and tool is under the MIT License. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexliubj%2Fezanchor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexliubj%2Fezanchor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexliubj%2Fezanchor/lists"}