{"id":26601996,"url":"https://github.com/keshavvishwkarma/kvconstraintkit","last_synced_at":"2025-10-06T01:06:38.368Z","repository":{"id":56917666,"uuid":"65222639","full_name":"keshavvishwkarma/KVConstraintKit","owner":"keshavvishwkarma","description":"An Impressive Auto Layout DSL for  iOS, tvOS \u0026 OSX. \u0026 It is written in pure swift.","archived":false,"fork":false,"pushed_at":"2019-03-05T14:24:34.000Z","size":7651,"stargazers_count":92,"open_issues_count":1,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-22T10:34:23.572Z","etag":null,"topics":["auto","autolayout","carthage","constraint","constraint-extension","constraint-solver","constraintkit","constraints","dsl","ios","kvconstraintkit","layout","layout-guide","nslayoutconstraint","osx","swift-extensions","swift-library","tvos","view"],"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/keshavvishwkarma.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-08-08T16:58:46.000Z","updated_at":"2024-06-03T12:42:47.000Z","dependencies_parsed_at":"2022-08-21T04:50:48.360Z","dependency_job_id":null,"html_url":"https://github.com/keshavvishwkarma/KVConstraintKit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/keshavvishwkarma/KVConstraintKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshavvishwkarma%2FKVConstraintKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshavvishwkarma%2FKVConstraintKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshavvishwkarma%2FKVConstraintKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshavvishwkarma%2FKVConstraintKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keshavvishwkarma","download_url":"https://codeload.github.com/keshavvishwkarma/KVConstraintKit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keshavvishwkarma%2FKVConstraintKit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278542923,"owners_count":26004098,"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-10-05T02:00:06.059Z","response_time":54,"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":["auto","autolayout","carthage","constraint","constraint-extension","constraint-solver","constraintkit","constraints","dsl","ios","kvconstraintkit","layout","layout-guide","nslayoutconstraint","osx","swift-extensions","swift-library","tvos","view"],"created_at":"2025-03-23T18:47:12.260Z","updated_at":"2025-10-06T01:06:38.328Z","avatar_url":"https://github.com/keshavvishwkarma.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KVConstraintKit\n[![CI Status](http://img.shields.io/travis/keshavvishwkarma/KVConstraintKit.svg?style=flat)](https://travis-ci.org/keshavvishwkarma/KVConstraintKit)\n[![Version](https://img.shields.io/cocoapods/v/KVConstraintKit.svg?style=flat)](http://cocoapods.org/pods/KVConstraintKit)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-Compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)\n![Swift 3.x](https://img.shields.io/badge/Swift-3.x-orange.svg)\n![Swift 4.x](https://img.shields.io/badge/Swift-4.x-orange.svg)\n[![License](https://img.shields.io/cocoapods/l/KVConstraintKit.svg?style=flat)](http://cocoapods.org/pods/KVConstraintKit)\n[![Platform](https://img.shields.io/cocoapods/p/KVConstraintKit.svg?style=flat)](http://cocoapods.org/pods/KVConstraintKit)\n\nKVConstraintKit is a DSL to make easy \u0026 impressive Auto Layout constraints on iOS, tvOS \u0026 OSX with Swift\n\n![KVConstraintKit](./Assets/KVConstraintKit_small_big.png)\n## Installation\n\n### Using CocoaPods\n1. To integrate `KVConstraintKit` into your Xcode project using [CocoaPods](http://cocoapods.org), specify it to a target in your [Podfile](https://guides.cocoapods.org/using/the-podfile.html):\n\n```ruby\nuse_frameworks!\npod 'KVConstraintKit', '~\u003e 2.1'\n```\n\nIf you want to be on the bleeding edge, replace the last line with:\n\n```ruby\npod 'KVConstraintKit', :git =\u003e 'https://github.com/keshavvishwkarma/KVConstraintKit.git', :branch =\u003e 'master'\n```\n\n2.  Run `pod install` and open the open the `{Project}.xcworkspace` instead of the `{Project}.xcodeproj` file to launch Xcode.\n\n### Using Carthage\n1. To integrate KVConstraintKit into your Xcode project using Carthage, specify it in your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile):\n\n```ogdl\ngithub \"keshavvishwkarma/KVConstraintKit\" ~\u003e 2.1\n```\n\n2. Run `carthage update` and follow [the additional steps](https://github.com/Carthage/Carthage#getting-started) in order to add `KVConstraintKit` to your project.\n\n## Auto Layout Attributes\n`KVConstraintKit` supports all built-in layout attributes as of iOS, tvOS \u0026 OSX, see the [NSLayoutAttribute](https://developer.apple.com/documentation/uikit/nslayoutconstraint.attribute) enum.\n\u003cp align=\"center\"\u003e \u003cimg src=\"./Assets/ios\u0026tvos_icon.png\" /\u003e \u003c/p\u003e\n\n## Usage\n\nHere's a quick example:\n##### Without Using KVConstraintKit\n```swift\nlet v = UIView.prepareAutoLayoutView()\nv.backgroundColor = UIColor.red\nview.addSubview(v)\n\n// Prepare constraints and then add them on superview of view\nlet top = NSLayoutConstraint( item: v, attribute: .top,\n                         relatedBy: .equal,\n                            toItem: v.superview!, attribute: .top,\n                        multiplier: 1.0, constant: 0)\n\nlet leading = NSLayoutConstraint( item: v, attribute: .leading,\n                             relatedBy: .equal,\n                                toItem: v.superview!, attribute: .leading,\n                            multiplier: 1.0, constant: 0)\n\nlet trailing = NSLayoutConstraint( item: v, attribute: .trailing,\n                         relatedBy: .equal,\n                            toItem: v.superview!, attribute: .trailing,\n                        multiplier: 1.0, constant: 0)\n\nlet bottom = NSLayoutConstraint( item: v, attribute: .bottom,\n                         relatedBy: .equal,\n                            toItem: v.superview!, attribute: .bottom,\n                        multiplier: 1.0, constant: 0)\n\nv.superview?.addConstraints([top, leading, trailing, bottom])\n```\n\n##### Using KVConstraintKit\n```swift\nv +== [.top, .leading, .trailing, .bottom]\n```\n##### Similarly for margin constraints\n```swift\nv +== [ .leadingMargin, .trailingMargin, .topMargin, .bottomMargin]\n```\n\n### Fit\nHorizontally\n\n```swift\nview.fitHorizontallyToSuperview()\nOR\nview.fitHorizontallyToSuperview(20) // padding\n```\nVertically\n\n```swift\nview.fitVerticallyToSuperview()\nOR\nview.fitVerticallyToSuperview(20) // padding\n```\nHorizontally \u0026 Vertically\n\n```swift\nview.fitToSuperview()\nOR\nview.fitToSuperview(20) // width same padding for all edge\n```\n\nFit with inset\n\n```swift\nlet inset = UIEdgeInsets(top: 4, left: 8, bottom: 12, right: 16)    \nview.fitToSuperview(contentInset:inset)\n```\n### Center\n\nHorizontally\n\n```swift\nview.applyCenterX()\nOR\nview.applyCenterX(20) // X offset\n```\nVertically\n\n```swift\nview.applyCenterY()\nOR\nview.applyCenterY(20) // Y offset\n```\nHorizontally \u0026 Vertically\n\n```swift\nview.applyCenter()\nOR\nview.applyCenter(CGPoint(x:20, y:20)) // XY offset\nOR\nview.applyCenterX(4).applyCenterY(16) // XY offset\n```\n### Size\n\nWidth\n\n```swift\nview.applyWidth(100)\nOR\nview.applyAtLeastWidth(100)\nOR\nview.applyAtMostWidth(100)\n```\n\nHeight\n\n```swift\nview.applyHeight(100)\nOR\nview.applyAtLeastHeight(100)\nOR\nview.applyAtMostHeight(100)\n```\n\nAspact Ratio\n\n```swift\nview.applyAspectRatio()\n```\n\n#### Quick Reference\n\n\u003ctable style=\"width:100%\"\u003e\n\u003ctr style=\"text-align: center\"\u003e \n\u003c!--    \u003cth width=\"20%\" \u003e Layout Attributes width Sketch \u003c/th\u003e --\u003e \n\u003cth width=\"20%\" align=center valign=middle\u003e Layout Attributes \u003c/th\u003e\n\u003cth width=\"40%\" align=center valign=middle\u003e Using Operator    \u003c/th\u003e\n\u003cth width=\"40%\" align=center valign=middle\u003e Using Method      \u003c/th\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eLeading\u003c/code\u003e \u003cimg src=\"./Assets/leading_pin.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003e(subview +== .leading).constant = 20\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyLeading(20)\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eTrailing\u003c/code\u003e \u003cimg src=\"./Assets/trailing_pin.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003e(subview +== .trailing).constant = 20\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyTrailing(20)\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eTop\u003c/code\u003e \u003cimg src=\"./Assets/top_pin.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003e(subview +== .top).constant = 20\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyTop(20) \u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eBottom\u003c/code\u003e \u003cimg src=\"./Assets/bottom_pin.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003e(subview +== .bottom).constant = 20\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyBottom(20)\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eCenterX\u003c/code\u003e \u003cimg src=\"./Assets/center_x.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview +== .centerX\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyCenterX()\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eCenterY\u003c/code\u003e \u003cimg src=\"./Assets/center_y.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview +== .centerY\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyCenterY()\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eHeight\u003c/code\u003e \u003cimg src=\"./Assets/height.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview +== (.height, 100)\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyHeight(100)\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eWidth\u003c/code\u003e \u003cimg src=\"./Assets/width.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview +== (.width, 100)\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyWidth(100)\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr style=\"text-align: center\"\u003e\n\u003ctd width=\"20%\" align=center valign=middle\u003e \u003ccode\u003eCenterX \u0026 CenterY\u003c/code\u003e \u003cimg src=\"./Assets/center_xy.png\"/\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview +== [.centerX, .centerY]\u003c/code\u003e \u003c/td\u003e\n\u003ctd width=\"40%\" align=center valign=middle\u003e \u003ccode\u003esubview.applyCenter()\u003c/code\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\nFor more details see the [ApplyViewConstraint](./KVConstraintKit/ApplyViewConstraint.swift) extension and [LayoutRelationable Protocol](./KVConstraintKit/KVConstraintKitProtocol.swift) of `KVConstraintKit`.\n\n**Note:** Avoid using **Left** and **Right** attributes. Use **Leading** and **Trailing** instead. This allows the layout to adapt to the view’s reading direction. By default the reading direction is determined based on the current language set by the user.\n\n## Custom Operators\nThe following types of `operators` are provided by `KVConstraintKit`, to `add`, `remove`, `access` and `modify` constraints.\n\n| Operator | Meaning |\n| :--------: |-------|\n|   +   | to `add` constraint |\n|   -   | to `remove` constraint |\n|   *   | to modify `multiplier` of constraint |\n|   ~   | to modify `Priority` ( **UILayoutPriority** ), `Relation` ( **NSLayoutRelation** ) \u0026 `Replace` constraint|\n|  \u003c-   | to access constraint by attributes ( **eg. NSLayoutAttribute.Height** ) |\n|  +==  | to add equal relation ( **NSLayoutRelation.Equal** ) constraint |\n|  +\u003e=  | to add greater than or equal relation ( **NSLayoutRelation.GreaterThanOrEqual** ) constraint |\n|  +\u003c=  | to add less than or equal relation ( **NSLayoutRelation.LessThanOrEqual** ) constraint |\n|  *==  | to add equal relation constraint with `multiplier` |\n|  *\u003e=  | to add greater than or equal relation constraint with `multiplier` |\n|  *\u003c=  | to add less than or equal relation constraint with `multiplier` |\n| \u0026#124;==\u0026#124; | to add or equal relation constraint between sibling views |\n| \u0026#124;\u003e=\u0026#124; | to add greater than or equal relation constraint between sibling views |\n| \u0026#124;\u003c=\u0026#124; | to add less than or equal relation constraint between sibling views |\n\n## License\n\n`KVConstraintKit` is available under the MIT license. See the LICENSE file for more info.\n\n## Contributions\n\nAny contribution is more than welcome! You can contribute through pull requests and issues on GitHub.\n\n## Author\n\nIf you wish to contact me, email at: keshavvbe@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeshavvishwkarma%2Fkvconstraintkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeshavvishwkarma%2Fkvconstraintkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeshavvishwkarma%2Fkvconstraintkit/lists"}