{"id":1279,"url":"https://github.com/Skyvive/Swiftstraints","last_synced_at":"2025-08-06T13:32:57.783Z","repository":{"id":31932651,"uuid":"35502155","full_name":"Skyvive/Swiftstraints","owner":"Skyvive","description":"Auto Layout In Swift Made Easy","archived":false,"fork":false,"pushed_at":"2022-11-10T21:47:30.000Z","size":89,"stargazers_count":122,"open_issues_count":1,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-07T06:44:52.700Z","etag":null,"topics":[],"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/Skyvive.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":"2015-05-12T17:18:48.000Z","updated_at":"2024-05-05T14:42:03.000Z","dependencies_parsed_at":"2022-08-25T05:50:52.672Z","dependency_job_id":null,"html_url":"https://github.com/Skyvive/Swiftstraints","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyvive%2FSwiftstraints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyvive%2FSwiftstraints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyvive%2FSwiftstraints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skyvive%2FSwiftstraints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Skyvive","download_url":"https://codeload.github.com/Skyvive/Swiftstraints/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":215780271,"owners_count":15929791,"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":[],"created_at":"2024-01-05T20:15:42.814Z","updated_at":"2024-08-17T16:30:59.789Z","avatar_url":"https://github.com/Skyvive.png","language":"Swift","funding_links":[],"categories":["Layout","Libs","UI","UI and SwiftUI","Layout [🔝](#readme)"],"sub_categories":["Other Hardware","Layout","Other free courses"],"readme":"# Swiftstraints\n\n`Swiftstraints` can turn verbose auto-layout code:\n```swift\nlet constraint = NSLayoutConstraint(item: blueView,\n                               attribute: NSLayoutAttribute.Width,\n                               relatedBy: NSLayoutRelation.Equal,\n                                  toItem: redView,\n                               attribute: NSLayoutAttribute.Width,\n                              multiplier: 1.0,\n                                constant: 0.0)\n```\nInto one just one line of code:\n```swift\nlet constraint = blueView.widthAnchor == redView.widthAnchor\n```\nOr transform your less than consise visual format language code:\n```swift\nlet constraints = NSLayoutConstraint.constraintsWithVisualFormat(\"H:|[leftView]-10-[rightView]|\",\n                               options: NSLayoutFormatOptions(0),\n                               metrics: nil,\n                               views: [\"leftView\":leftView, \"rightView\":rightView])\n```\nInto the following:\n``` swift\nlet constraints = NSLayoutConstraints(\"H:|[\\(leftView)]-10-[\\(rightView)]|\")\n```\nThat was easy!\n\n## Installation\n\n`Swiftstraints` is available through [CocoaPods](http://cocoapods.org). To install, simply include the following lines in your podfile:\n```ruby\nuse_frameworks!\npod 'Swiftstraints'\n```\nBe sure to import the module at the top of your .swift files:\n```swift\nimport Swiftstraints\n```\nAlternatively, clone this repo or download it as a zip and include the classes in your project.\n\n## Constraints\n\nWith `Swiftstraints` you can create constraints that look just Apple's generic constraint definition:\n```swift\nitem1.attribute1 = multiplier × item2.attribute2 + constant\n```\n`Swifstraints` utilizes the new layout anchors introduced in iOS 9:\n```swift\nlet view = UIView()\nview.widthAnchor\nview.heightAnchor\nview.trailingAnchor\nview.centerXAnchor\netc...\n```\n`Swiftstraints` implements operator overloading so that you can easily create custom constraints:\n```swift\nlet blueView = UIView()\nlet redView = UIView()\nlet constraint = blueView.heightAnchor == redView.heightAnchor\n```\nJust as you would expect, you can specify a multiplier:\n```swift\nlet constraint = blueView.heightAnchor == 2.0 * redView.heightAnchor\n```\nOr add a constant:\n```swift\nlet constraint = blueView.heightAnchor == redView.heightAnchor + 10.0\n```\nYou can specify inequalities:\n```swift\nlet constraint = blueView.heightAnchor \u003c= redView.heightAnchor\n```\nAnd you can define constant constraints if you so choose:\n```swift\nlet constraint = blueView.heightAnchor == 100.0\n```\nSwiftstraints can readily compute relatively complex constraints:\n```swift\nlet constraint = blueView.heightAnchor * 1.4 - 5.0 \u003e= redView.heightAnchor / 3.0 + 400\n```\nIt's really easy.\n\n## Visual Format Language\n\nApple provides an API that lets you create multiple constraints simultaneously with the Visual Format Language. As we saw before it can be a little cumbersome:\n```swift\nlet constraints = NSLayoutConstraint.constraintsWithVisualFormat(\"H:|[leftView]-10-[rightView]|\",\n                               options: NSLayoutFormatOptions(0),\n                               metrics: nil,\n                               views: [\"leftView\":leftView, \"rightView\":rightView])\n```\n`Swiftstraints` uses string interpolation to let you specify the same constraints in one line of code:\n```swift\nlet constraints = NSLayoutConstraints(\"H:|[\\(leftView)]-10-[\\(rightView)]|\")\n```\n`Swiftstraints` also extends `UIView` so that you can add constraints easily using the interpolated string format:\n```swift\nsuperview.addConstraints(\"H:|[\\(leftView)]-10-[\\(rightView)]|\")\n```\nSuper easy, super simple.\n## Revision History\n\n* 3.0.1 - Bug fixes and limited iOS 8 support (Thank you catjia1011)\n* 3.0.0 - Updated to Swift 3\n* 2.2.0 - Added support for UILayoutPriority\n* 2.1.0 - Fixed a view reference bug and added a new convenience method for adding constraints\n* 2.0.2 - Added support for tvOS target.\n* 2.0.1 - Updated to include support for axis anchors, increased test coverage and more documentation.\n* 2.0.0 - Updated for Swift 2.0 and iOS 9. Now uses layout anchors for simple constraints and string interpolation for Visual Format Language constraints.\n* 1.1.0 - Minor API tweaks\n* 1.0.0 - Initial Release\n\n## Author\n\nBrad Hilton, brad.hilton.nw@gmail.com\n\n## License\n\nSwiftstraints is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSkyvive%2FSwiftstraints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSkyvive%2FSwiftstraints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSkyvive%2FSwiftstraints/lists"}