Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
noremac/Layout
Layout
An expressive and extensible DSL for creating Auto Layout constraints and defining declarative layouts.
Creating Constraints
// Creating inactive constraints (save and activate/manipulate later)
let constraints = view.makeConstraints(
.center(),
.size(CGSize(width: 100, height: 100))
)
// Creating active constraints
view.applyConstraints(
.center(),
.size(CGSize(width: 100, height: 100))
)
UIView
and UILayoutGuide
makeConstraints
and applyConstraints
operate on both UIView
and UILayoutGuide
. All constraints that are setup up in relation to other items may also be either UIView
or UILayoutGuide
.
button.applyConstraints(
.center(in: view.safeAreaLayoutGuide), // relating to a `UILayoutGuide`
.relativeSize(of: otherButton) // relating to a `UIView`
)
Constraints that are related to another item default to the receiver’s parent view. Therefore, the following two examples are identical:
// Preferred
button.applyConstraints(
.center()
)
// Not-preferred
button.applyConstraints(
.center(in: button.superview)
)
Autoresizing Mask
Layout sets translatesAutoresizingMaskIntoConstraints
to false
on the receiver of the makeContstraints
and applyConstraints
calls.
Debugging Constraints
Layout has the ability to add debug identifiers to all constraints that include the file, function, and line number of where the constraint was created. If you are having trouble with ambiguous constraints, you can enable these identifiers like this:
// Call this in your AppDelegate
ConstraintGroup.debugConstraints = true
Declarative Layout
wip
Installation
CocoaPods
Layout has not yet been published as a CocoaPod, but you may still use it.
To integrate Layout into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'Layout', :git => 'git@github.com:/noremac/Layout.git', :tag => '0.0.2'
Carthage
To integrate Layout into your Xcode project using Carthage, specify it in your Cartfile:
github "noremac/Layout"
Run carthage update
to build the framework and drag the built
Layout.framework
into your Xcode project.
License
This code and tool is under the MIT License. See LICENSE
file in this repository.