pauljohanneskraft / SimpleConstraints

Constraints made easy - with simple equations and many operator overloads

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SimpleConstraints

SimpleConstraints

Version Platform License

Constraints have been hard to create in code for a long time. The default UIKit way would be the following:

let viewA = UIView()
let viewB = UIView()

# Before iOS 9

let constraint = NSLayoutConstraint(item: viewA, attribute: .top, relatedBy: .equal, toItem: viewB, attribute: .bottom, multiplier: 1, constant: 0)

# After iOS 9

let constraint = viewA.topAnchor.constraint(equalTo: viewB.bottomAnchor)

While layout anchors made the creation a lot easier, it is still not as intuitive as it could be. Introducing: SimpleConstraints.

With SimpleConstraints, you can create NSLayoutConstraints like mathematical equations as in the following:

let viewA = UIView()
let viewB = UIView()

let constraint = viewA.heightAnchor * 5 - 3 <= viewB.widthAnchor + 25

With many operator overloads, some UIView-extensions for most commonly used constraints and also NSLayoutConstraint-extensions, SimpleConstraints is designed to simplify the handling of UI without the need of storyboards or .xib-files.

Installation

SimpleConstraints is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SimpleConstraints'

Author

pauljohanneskraft

License

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

About

Constraints made easy - with simple equations and many operator overloads

License:MIT License


Languages

Language:Swift 96.8%Language:Ruby 3.2%