ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - keshavvishwkarma/KVConstraintKit: An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.
An Impressive Auto Layout DSL for  iOS, tvOS & OSX. & It is written in pure swift. - keshavvishwkarma/KVConstraintKit
Visit Site

GitHub - keshavvishwkarma/KVConstraintKit: An Impressive Auto Layout DSL for  iOS, tvOS & OSX. & It is written in pure swift.

GitHub - keshavvishwkarma/KVConstraintKit: An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.

KVConstraintKit

CI Status Version Carthage compatible Swift 3.x Swift 4.x License Platform

KVConstraintKit is a DSL to make easy & impressive Auto Layout constraints on iOS, tvOS & OSX with Swift

KVConstraintKit

Installation

Using CocoaPods

  1. To integrate KVConstraintKit into your Xcode project using CocoaPods, specify it to a target in your Podfile:
use_frameworks!
pod 'KVConstraintKit', '~> 2.1'

If you want to be on the bleeding edge, replace the last line with:

pod 'KVConstraintKit', :git => 'https://github.com/keshavvishwkarma/KVConstraintKit.git', :branch => 'master'
  1. Run pod install and open the open the {Project}.xcworkspace instead of the {Project}.xcodeproj file to launch Xcode.

Using Carthage

  1. To integrate KVConstraintKit into your Xcode project using Carthage, specify it in your Cartfile:
github "keshavvishwkarma/KVConstraintKit" ~> 2.1
  1. Run carthage update and follow the additional steps in order to add KVConstraintKit to your project.

Auto Layout Attributes

KVConstraintKit supports all built-in layout attributes as of iOS, tvOS & OSX, see the NSLayoutAttribute enum.

Usage

Here's a quick example:

Without Using KVConstraintKit
let v = UIView.prepareAutoLayoutView()
v.backgroundColor = UIColor.red
view.addSubview(v)

// Prepare constraints and then add them on superview of view
let top = NSLayoutConstraint( item: v, attribute: .top,
                         relatedBy: .equal,
                            toItem: v.superview!, attribute: .top,
                        multiplier: 1.0, constant: 0)

let leading = NSLayoutConstraint( item: v, attribute: .leading,
                             relatedBy: .equal,
                                toItem: v.superview!, attribute: .leading,
                            multiplier: 1.0, constant: 0)

let trailing = NSLayoutConstraint( item: v, attribute: .trailing,
                         relatedBy: .equal,
                            toItem: v.superview!, attribute: .trailing,
                        multiplier: 1.0, constant: 0)

let bottom = NSLayoutConstraint( item: v, attribute: .bottom,
                         relatedBy: .equal,
                            toItem: v.superview!, attribute: .bottom,
                        multiplier: 1.0, constant: 0)

v.superview?.addConstraints([top, leading, trailing, bottom])
Using KVConstraintKit
v +== [.top, .leading, .trailing, .bottom]
Similarly for margin constraints
v +== [ .leadingMargin, .trailingMargin, .topMargin, .bottomMargin]

Fit

Horizontally

view.fitHorizontallyToSuperview()
OR
view.fitHorizontallyToSuperview(20) // padding

Vertically

view.fitVerticallyToSuperview()
OR
view.fitVerticallyToSuperview(20) // padding

Horizontally & Vertically

view.fitToSuperview()
OR
view.fitToSuperview(20) // width same padding for all edge

Fit with inset

let inset = UIEdgeInsets(top: 4, left: 8, bottom: 12, right: 16)    
view.fitToSuperview(contentInset:inset)

Center

Horizontally

view.applyCenterX()
OR
view.applyCenterX(20) // X offset

Vertically

view.applyCenterY()
OR
view.applyCenterY(20) // Y offset

Horizontally & Vertically

view.applyCenter()
OR
view.applyCenter(CGPoint(x:20, y:20)) // XY offset
OR
view.applyCenterX(4).applyCenterY(16) // XY offset

Size

Width

view.applyWidth(100)
OR
view.applyAtLeastWidth(100)
OR
view.applyAtMostWidth(100)

Height

view.applyHeight(100)
OR
view.applyAtLeastHeight(100)
OR
view.applyAtMostHeight(100)

Aspact Ratio

view.applyAspectRatio()

Quick Reference

For more details see the ApplyViewConstraint extension and LayoutRelationable Protocol of KVConstraintKit.

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.

Custom Operators

The following types of operators are provided by KVConstraintKit, to add, remove, access and modify constraints.

Operator Meaning
+ to add constraint
- to remove constraint
* to modify multiplier of constraint
~ to modify Priority ( UILayoutPriority ), Relation ( NSLayoutRelation ) & Replace constraint
<- to access constraint by attributes ( eg. NSLayoutAttribute.Height )
+== to add equal relation ( NSLayoutRelation.Equal ) constraint
+>= to add greater than or equal relation ( NSLayoutRelation.GreaterThanOrEqual ) constraint
+<= to add less than or equal relation ( NSLayoutRelation.LessThanOrEqual ) constraint
*== to add equal relation constraint with multiplier
*>= to add greater than or equal relation constraint with multiplier
*<= to add less than or equal relation constraint with multiplier
|==| to add or equal relation constraint between sibling views
|>=| to add greater than or equal relation constraint between sibling views
|<=| to add less than or equal relation constraint between sibling views

License

KVConstraintKit is available under the MIT license. See the LICENSE file for more info.

Contributions

Any contribution is more than welcome! You can contribute through pull requests and issues on GitHub.

Author

If you wish to contact me, email at: [email protected]

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory