{"id":15038069,"url":"https://github.com/roberthein/tinyconstraints","last_synced_at":"2025-05-14T04:10:36.515Z","repository":{"id":41142744,"uuid":"81009175","full_name":"roberthein/TinyConstraints","owner":"roberthein","description":"Nothing but sugar.","archived":false,"fork":false,"pushed_at":"2024-04-16T15:06:27.000Z","size":37466,"stargazers_count":4047,"open_issues_count":23,"forks_count":200,"subscribers_count":54,"default_branch":"master","last_synced_at":"2025-05-11T16:01:59.271Z","etag":null,"topics":["animation","arkit","auto","center","constraint","constraints","layout","libraries","library","nslayoutconstraint","nslayoutconstraints","stack","sugar","superview","sweet","swift","swift-5","swift4","swift5","syntactic"],"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/roberthein.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-05T17:33:40.000Z","updated_at":"2025-05-09T11:22:38.000Z","dependencies_parsed_at":"2022-07-13T19:30:32.082Z","dependency_job_id":"554d0532-bbe4-4e1c-9250-0ccf623e77e3","html_url":"https://github.com/roberthein/TinyConstraints","commit_stats":{"total_commits":156,"total_committers":28,"mean_commits":5.571428571428571,"dds":0.532051282051282,"last_synced_commit":"a89996a77d364eb85abdd09d42d2274e35ba56dc"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberthein%2FTinyConstraints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberthein%2FTinyConstraints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberthein%2FTinyConstraints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roberthein%2FTinyConstraints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roberthein","download_url":"https://codeload.github.com/roberthein/TinyConstraints/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254070125,"owners_count":22009560,"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":["animation","arkit","auto","center","constraint","constraints","layout","libraries","library","nslayoutconstraint","nslayoutconstraints","stack","sugar","superview","sweet","swift","swift-5","swift4","swift5","syntactic"],"created_at":"2024-09-24T20:36:58.647Z","updated_at":"2025-05-14T04:10:31.504Z","avatar_url":"https://github.com/roberthein.png","language":"Swift","readme":"**TinyConstraints** is the syntactic sugar that makes Auto Layout sweeter for human use.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"Art/header.png\" width=\"890\" alt=\"TinyConstraints\"/\u003e\n\u003c/p\u003e\n\n## Features\n\n- [X] Pure Swift 5 sweetness.\n- [X] Everything you can do with Auto Layout, but shorter.\n- [X] Constraints are active by default.\n- [X] 100% compatible with other Auto Layout code.\n- [X] Optionally store your constraints.\n- [X] Set constraint priorities upon creation.\n- [X] Constrain directly to the superview.\n- [X] Stack views together with one line of code.\n- [X] No need to set `translatesAutoresizingMaskIntoConstraints` because `TinyConstraints` does it for you.\n\n## Examples\n### Edges\nAttaching a view to its superview with `NSLayoutConstraint`:\n\n```swift\nNSLayoutConstraint.activate([\n    view.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0),\n    view.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0),\n    view.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0),\n    view.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0)\n])\n```\n\nwith `TinyConstraints`:\n\n```swift\nview.edgesToSuperview()\n```\n\nor:\n\n```swift\nview.edgesToSuperview(insets: .top(10) + .left(10))\n```\n### Center\nConstraining the center of a view to its superview with `NSLayoutConstraint`:\n\n```swift\nNSLayoutConstraint.activate([\n    view.centerXAnchor.constraint(equalTo: superview.centerXAnchor, constant: 0)\n    view.centerYAnchor.constraint(equalTo: superview.centerYAnchor, constant: 0)\n])\n```\n\nwith `TinyConstraints`:\n\n```swift\nview.center(in: superview)\n```\n\nor:\n\n```swift\nview.center(in: superview, offset: CGPoint(x: 10, y: 10))\n```\n\n## Basic Use\n\n### Typealiases\n\n`TinyConstraints` gives you convenient and tiny typealiases for handling constraints.\n\n- `Constraint` = `NSLayoutConstraint`\n- `Constraints` = `[NSLayoutConstraint]`\n\n### Equal and Unequal Anchors\nThis constraints the `top-anchor` of the view to the `top-anchor` of the superview:\n\n```swift\nview.top(to: superview)\n```\n\nThis constraints the `top-anchor` of `firstView` to the `bottom-anchor` of `secondView`:\n\n```swift\nfirstView.topToBottom(of: secondView)\n```\n\n### Constrain to Superview\nOften you need to constrain a view to it's superview, with TinyConstraints you can do this super easy:\n\n```swift\nview.edgesToSuperview()\n```\n\nOr only one edge:\n\n```swift\nview.topToSuperview()\n```\n\nOr you can attach all edges except one, like this:\n\n```swift\nview.edgesToSuperview(excluding: .bottom)\n```\n\n### Relation and Priority\nFor almost all constraints you can set the `relation` and `priority` properties. The default relation is `.equal` and the default priority is `.required`:\n\n```swift\ncontainer.width(150, relation: .equalOrLess, priority: .high)\n```\n\n### Storing Constraints\nHere we create a set of inactive constraints and store these to our property:\n\n```swift\nlet constraints = view.size(CGSize(width: 100, height: 100), isActive: false)\n```\n\n### Activation and Deactivation\nBesides the default `NSLayoutConstraint` activation, `TinyConstraints` also provides a way to activate *a set* of constraints:\n\n```swift\nconstraints.activate()\n```\n\nYou can also do this in an animation:\n\n```swift\noldConstraints.deActivate()\n\nconstraints.activate()\nUIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) {\n    self.layoutIfNeeded()\n}.startAnimation()\n```\n\n### Animating Constraint Constants\nHere we add a height constraint to a view, store it and animate it later:\n\n```swift\nlet height = view.height(100)\n\nheight.constant = 200\nUIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) {\n    self.layoutIfNeeded()\n}.startAnimation()\n```\n\n### Stack\nStack provides a way of constraining views together in a superview:\n\n```swift\nlet views = [logo, title, description]\nsuperview.stack(views, axis: .vertical, spacing: 10)\n```\n\n##### Find these examples and more in the *Example Project*.\n\n## Installation\n\n### CocoaPods\n\nTinyConstraints is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"TinyConstraints\"\n```\n\n### Carthage\n\nTinyConstraints is available through [Carthage](https://github.com/Carthage/Carthage). To install\nit, simply add the following line to your Cartfile:\n\n```\ngithub \"roberthein/TinyConstraints\"\n```\n\n### Swift Package Manager\n\nTinyConstraints is available through [Swift Package Manager](https://swift.org/package-manager/). To install\nit, in Xcode 11.0 or later select `File` \u003e `Swift Packages` \u003e `Add Package Dependency...` and add TinyConstraints repository URL:\n```\nhttps://github.com/roberthein/TinyConstraints.git\n```\n\n## Tutorials\n\nHere are some [video tutorials](https://www.youtube.com/playlist?list=PL_csAAO9PQ8ZDbGk57RlBRnNpxBGBAEOc) made by [Alex Nagy](https://github.com/rebeloper).\n\n\n## Suggestions or feedback?\n\nFeel free to create a pull request, open an issue or find [me on Twitter](https://twitter.com/roberthein).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberthein%2Ftinyconstraints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froberthein%2Ftinyconstraints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froberthein%2Ftinyconstraints/lists"}