{"id":1309,"url":"https://github.com/huri000/QuickLayout","last_synced_at":"2025-08-02T04:30:51.437Z","repository":{"id":48856581,"uuid":"111331656","full_name":"huri000/QuickLayout","owner":"huri000","description":"Written in pure Swift, QuickLayout offers a simple and easy way to manage Auto Layout in code.","archived":false,"fork":false,"pushed_at":"2021-10-17T11:57:14.000Z","size":15575,"stargazers_count":251,"open_issues_count":2,"forks_count":38,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-27T06:48:19.540Z","etag":null,"topics":["autolayout","autolayout-constraints","interface-builder","manage-constraints","nslayoutconstraint","swift","uiview","uiviewextension"],"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/huri000.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-19T21:01:05.000Z","updated_at":"2025-02-27T22:56:10.000Z","dependencies_parsed_at":"2022-08-23T16:10:42.391Z","dependency_job_id":null,"html_url":"https://github.com/huri000/QuickLayout","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/huri000/QuickLayout","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huri000%2FQuickLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huri000%2FQuickLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huri000%2FQuickLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huri000%2FQuickLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huri000","download_url":"https://codeload.github.com/huri000/QuickLayout/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huri000%2FQuickLayout/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334607,"owners_count":24233793,"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-08-02T02:00:12.353Z","response_time":74,"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":["autolayout","autolayout-constraints","interface-builder","manage-constraints","nslayoutconstraint","swift","uiview","uiviewextension"],"created_at":"2024-01-05T20:15:43.489Z","updated_at":"2025-08-02T04:30:51.014Z","avatar_url":"https://github.com/huri000.png","language":"Swift","readme":"# QuickLayout\n\n[![Platform](https://img.shields.io/cocoapods/p/QuickLayout.svg?style=flat)](http://cocoapods.org/pods/QuickLayout)\n[![Language](http://img.shields.io/badge/language-Swift-brightgreen.svg?style=flat\n)](https://developer.apple.com/swift)\n![](https://travis-ci.org/huri000/QuickLayout.svg?branch=master)\n[![Version](https://img.shields.io/cocoapods/v/QuickLayout.svg?style=flat-square)](http://cocoapods.org/pods/QuickLayout)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![SwiftPM Compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![Accio: Supported](https://img.shields.io/badge/Accio-supported-0A7CF5.svg?style=flat)](https://github.com/JamitLabs/Accio)\n[![codecov](https://codecov.io/gh/huri000/QuickLayout/branch/master/graph/badge.svg)](https://codecov.io/gh/huri000/QuickLayout)\n[![License](https://img.shields.io/cocoapods/l/QuickLayout.svg?style=flat-square)](http://cocoapods.org/pods/QuickLayout)\n\n![image](https://github.com/huri000/assets/blob/master/quick-layout/logo.png)\n\nQuickLayout offers an additional way, to easily manage the Auto Layout using only code.\nYou can harness the power of QuickLayout to align your interface programmatically without even creating constraints explicitly.\n\n* [The WHY](#the-why)\n* [Naming Convension](#naming-convension)\n* [Features](#features)\n* [Example Project](#example-project)\n* [Requirements](#requirements)\n* [Installation](#installation)\n  * [CocoaPods](#cocoapods)\n  * [Carthage](#carthage)\n  * [Swift Package Manager](#swift-package-manager)\n  * [Accio](#accio)\n  * [Manually](#manually)\n* [Usage](#usage)\n  * [Constant edges](#constant-edges)\n  * [Layout to Superview](#layout-to-superview)\n    * [Layout edge-x to superview edge-x](#layout-edge-x-to-superview-edge-x)\n    * [Using the applied constraint](#using-the-applied-constraint)\n    * [Ratio](#ratio)\n    * [Offset](#offset)\n    * [Center](#center)\n    * [Size](#size)\n    * [Fill](#fill)\n    * [Axis](#axis)\n  * [Layout to View](#layout-to-view)\n    * [Edge-x to edge-x of another view](#edge-x-to-edge-x-of-another-view)\n    * [Multiple edges](#multiple-edges)\n  * [Content Wrap](#content-wrap)\n  * [Array of QLView Elements](#array-of-uiview-elements)\n    * [Constant edges](#constant-edges)\n    * [Axis](#axis)\n    * [Multiple edges](#multiple-edges)\n    * [Spread views](#spread-views)\n  * [More](#more)\n    * [Priority](#priority)\n    * [Relation](#relation)\n    * [Ratio](#ratio)\n    * [Offset](#offset)\n  * [Explicit Layout](#explicit-layout)\n\n## The **WHY**\nWhy should you use QuickLayout?\n- QuickLayout  drastically shortens the amount of code in case you ever need to write the view hierarchy.\n- It provides a common Auto Layout API for iOS, tvOS and macOS.\n- QuickLayout contains most of the Auto Layout constructs an iOS App requires.\n- The QuickLayout method declarations are very descriptive and clear. It is fully documented!\n- Layout a `UIView` or `NSView` or an array of views using the instances themselves, without even creating a single NSLayoutConstraint instance.\n\n## Naming Convension\nAs of version 2.0.0, QuickLayout supports tvOS and macOS as well as iOS. Therefore, a few adjustments have been made. \n- `QLView` replaces `UIView` or `NSView`.\n- `QLPriority` replaces `NSLayoutConstraint.Priority` and `UILayoutPriority`\n- `QLAttribute` replaces `NSLayoutConstraint.Attribute` and `NSLayoutAttribute`\n- `QLRelation` replaces `NSLayoutConstraint.Relation` and `NSLayoutRelation`\n\n## Features\n- Extension to `QLView` that contains functionality that allows you to set constraints directly from the view itself.\n- Extension to `Array of QLView` that contains functionality that allows you to set constraints directly from an array of views.\n\n## Example Project\nThe example project demonstrates the benefits of using QuickLayout with several common use cases.\nHave a look! 😎\n\n## Requirements\n\nSwift 4.0 or any higher version.\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate QuickLayout into your Xcode project using CocoaPods, specify the following in your `Podfile`:\n\n```ruby\npod 'QuickLayout', '3.0.2'\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate QuickLayout into your Xcode project using Carthage, specify the following in your `Cartfile`:\n\n```ogdl\ngithub \"huri000/QuickLayout\" == 3.0.2\n```\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.\n\nUsing Xcode 11.0+ go to your project file and enter the project URL of this repository:\n```ogdl\nhttps://github.com/huri000/QuickLayout\n```\n\n### Accio\n\n[Accio](https://github.com/JamitLabs/Accio) is a decentralized dependency manager driven by SwiftPM that works for iOS/tvOS/watchOS/macOS projects.\n\nYou can install Accio with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew tap JamitLabs/Accio https://github.com/JamitLabs/Accio.git\n$ brew install accio\n```\n\nTo integrate QuickLayout into your Xcode project using Accio, specify the following in your `Package.swift` manifest:\n\n```swift\n.package(url: \"https://github.com/huri000/QuickLayout.git\", .exact(\"3.0.2\"))\n```\n\nAfter specifying `\"QuickLayout\"` as a dependency of the target in which you want to use it, run `accio install`.\n\n#### Manually\n\nAdd the [source files](https://github.com/huri000/QuickLayout/tree/master/QuickLayout) to your project.\n\n\n## Usage\n\nUsing QuickLayout is easy. No setup or preparation is required.\nAll the necessary methods are already available in any of the `QLView` instances, and are fully documented and highly descriptive.\n\n**First, some boilerplate code**: Define `simpleView` of type `QLView` and add it to the view hierarchy.\n\n```Swift\n// Create a view, add it to view hierarchy, and customize it\nlet simpleView = QLView()\nsimpleView.backgroundColor = .gray\nparentView.addSubview(simpleView)\n```\n\n### Constant edges\n\nSet a constant edge of a view:\n```Swift\nsimpleView.set(.height, of: 50)\n```\n\nYou can set multiple constant edges using [variadic parameters](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html):\n```Swift\nsimpleView.set(.width, .height, of: 100)\n```\n\n### Layout to Superview\n\nYou can easily layout a view directly to its superview as long as it has one.\n\n#### Layout edge-x to superview edge-x\n\nLayout the top of a view to the top of its superview:\n```Swift\nsimpleView.layoutToSuperview(.top)\n```\n\nLayout the centerX of a view to the centerX of its superview:\n```Swift\nsimpleView.layoutToSuperview(.centerX)\n```\n\n#### Multiple edges\n\nYou can also layout multiple edges likewise, using [variadic parameters](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html):\n```Swift\nsimpleView.layoutToSuperview(.top, .bottom, .centerX, .width)\n```\n\n#### Using the applied constraint\n\nAll the layout methods return the applied constraints, but the returned values are [discardable](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Attributes.html) so you can simply ignore them if you don't need them.\n```Swift    \nlet topConstraint = simpleView.layoutToSuperview(.top)\n```\n```Swift\n// Change the offset value by adding 10pts to it\ntopConstraint.constant += 10\n```\n\n#### Ratio\n\nYou can layout a view to 80% its superview width:\n```Swift    \nsimpleView.layoutToSuperview(.width, ratio: 0.8)\n```\n\n#### Offset\n\nYou can layout a view to it's superview width minus 10pts offset:\n```Swift    \nsimpleView.layoutToSuperview(.width, offset: -10)\n```\n\n#### Center\n\nLayout view to the center of superview:\n```Swift    \nlet center = simpleView.centerInSuperview()\n```\n\nYou can optionally retreive the returned `QLCenterConstraints` instance.\n\n```Swift\ncenter?.y.constant = 20\n```\n\nThat is the equivalent of doing the following, without getting the `QLCenterConstraints` instance (but an array of `NSLayoutConstraint` instead).\n```Swift\nsimpleView.layoutToSuperview(.centerX, .centerY)\n```\n\n#### Size\n\nSize to superview with optional ratio - It means that `simpleView` is 80% its superview size. \n```Swift    \nlet size = simpleView.sizeToSuperview(withRatio: 0.8)\n```\n\nYou can optionally retreive the returned `QLSizeConstraints`  instance.\n\n```Swift    \nsize?.width.constant = -20\n```\n\nThat is the equivalent of doing the following, without getting the `QLSizeConstraints` instance (but an array of `NSLayoutConstraint` instead).\n```Swift\nsimpleView.layoutToSuperview(.width, .height, ratio: 0.8)\n```\n\n#### Fill\n\n```Swift    \nlet fillConstraints = simpleView.fillSuperview()\n```\n\nYou can optionally retreive the returned `QLFillConstraints`  instance.\n\n```Swift\nfillConstraints?.center.y.constant = 5\n```\n\n#### Axis:\n\nYou can layout view to a certain axis, for example:\n\nHorizontally:\n```Swift\nlet axis = simpleView.layoutToSuperview(axis: .horizontally)\n```\n\nVertically:\n```Swift\nsimpleView.layoutToSuperview(axis: .vertically)\n```\n\nThat is equivalent to (Horizontally):\n```Swift\nsimpleView.layoutToSuperview(.left, .right)\n```\n\nOr (Vertically):\n\n```Swift\nsimpleView.layoutToSuperview(.top, .bottom)\n```\n\nYou can reteive the `QLAxisConstraints` instance as well and use it.\n\n### Layout to View\n\nIt is possible to layout one view to another inside the view hierarchy.\n\n#### Layout edge-x to edge-y of another view\n\nYou can layout an edge of a view to another. For example: \n\nLayout `simpleView`'s `left` edge to the `right` edge of  `anotherView`, with `20pts right offset`.\n\n```Swift\nsimpleView.layout(.left, to: .right, of: anotherView, offset: 20)\n```\n\n#### Edge-x to edge-x of another view\n\nLayout `simpleView`'s `top` edge to the `top` edge of  `anotherView`\n\n```Swift\nsimpleView.layout(to: .top, of: anotherView)\n```\n\n####  Multiple edges\n\nLayout `simpleView`'s left, right and centerY to `anotherView`'s left, right and centerY, respectively.\n\n```Swift\nsimpleView.layout(.left, .right, .centerY, to: anotherView)\n```\n\n### Content Wrap\n\nContent Hugging Oriority and Content Compression Resistance can be also mutated in code\n\nVertical example:\n```Swift\nlet label = UILabel()\nlabel.text = \"Hi There!\"\nlabel.verticalCompressionResistancePriority = .required\nlabel.verticalHuggingPriority = .required\n```\n\nYou can set the compression resistence and the hugging priority, together. Thus, forcing both to be `.required` vertically and horizontally. \n```Swift\nlabel.forceContentWrap()\n```\n\nYou can force content wrap a specific axis:\n\n```Swift\nlabel.forceContentWrap(.vertically)\n```\n\n### Array of `QLView` Elements\n\nYou can generate an array of views and apply constraints on them all in one shot.\n\n```Swift\n// Create array of views and customize it\nvar viewsArray: [QLView] = []\nfor _ in 0...4 {\n    let simpleView = QLView()\n    view.addSubview(simpleView)\n    viewsArray.append(simpleView)\n}\n```\n\n#### Constant edges\n\nEach element gets height of 50pts, using this single line of code.\n\n```Swift\nviewsArray.set(.height, of: 50)\n```\n\n#### Axis\n\nEach element cling to left and right of its superview.\n\n```Swift\nviewsArray.layoutToSuperview(axis: .horizontally, offset: 30)\n```\n\n#### Multiple edges\n\nEach element left, right, top, bottom edges is exactly fits another view.\n\n```Swift\nviewsArray.layout(.left, .right, .top, .bottom, to: parentView)\n```\n\n#### Spread views\n\nYou can spread the elements one below the other (vertically), the first stretches to the top of the superview and the last stretchs to the bottom of the superview. There is an offset of 1pt between each element. \n\n```Swift\nviewsArray.spread(.vertically, stretchEdgesToSuperview: true, offset: 1)\n```\n\n### More\n\nEvery layout method has several optional parameters - see below:\n\n####  Priority\n\n- The priority of the applied constraint. \n- Included by all the layout methods.\n- Default value: `.required`.\n\nOther than the default system priorities,  QuickLayout offers one more - it has 999 value and it's called  `.must`.\n\nYou can tweak the priorities as you like in order to deal with breakage and redundancies.\n\nExample for setting the constraints priority:\n\n```Swift\nlet width = simpleView.set(.width, of: 100, priority: .must)\n```\n\n#### Relation\n\n- The relation of a view to another view. \n- Included by most of the layout methods.\n- Default value: `.equal`\n\n#### Ratio\n\n- The ratio of a view to another view. \n- Included by most of the layout methods.\n- Default value: 1\n\n#### Offset\n\n- The offset of a view to another view. \n- Included by most of the layout methods.\n- Default value: 0\n\n### Explicit Layout\n\nYou can layout a view/s explicitly to a superview or another view when you need to.\nMost paramters have a default value.\n\n```Swift\nsimpleView.layout(.height, to: .width, of: anotherView, relation: .lessThanOrEqual, ratio: 0.5, offset: 10, priority: .defaultHigh)\n```\n\n## Contributing\n\nForks, patches and other feedback are welcome.\n\n## Author\n\nDaniel Huri (huri000@gmail.com)\n\n## License\n\nQuickLayout is available under the MIT license. See the LICENSE file for more info.\n\n","funding_links":[],"categories":["Layout","Swift"],"sub_categories":["Other Hardware"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuri000%2FQuickLayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuri000%2FQuickLayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuri000%2FQuickLayout/lists"}