Auto Layout convenience with minimal API surface area, but high expressive power
- Minimal API accessible through
constraint
proxy - Direct access to created
NSLayoutConstraint
-
UILayoutGuide
support - New
UILayoutPriority
constants including.maxNonRequired
(999) for resolving layout ambiguities -
translatesAutoresizingMaskIntoConstraints
is automatically set tofalse
on a target
subview.constraint.edges(to: view)
subview.constraint.edges(to: view, insets: .uniform(10))
subview.constraint.edges(excluding: .bottom, to: view, insets: .horizontal(10))
subview.constraint.edges(.bottom, .leading, to: view, insets: .leading(10))
subview.constraint.trailing(to: view)
subview.constraint.centerX(to: view)
subview.constraint.leading(to: view, .centerX)
subview.constraint.trailing(to: view, .leading, constant: 10)
subview.constraint.bottom(to: view)
subview.constraint.centerY(to: view)
subview.constraint.top(to: view, .centerY)
subview.constraint.bottom(to: view, .top, constant: 10)
subview.constraint.lastBaseline(to: view)
subview.constraint.center(to: view)
subview.constraint.size(CGSize(width: 75, height: 75))
subview.constraint.size(to: view)
subview.constraint.size(to: view, multiplier: 0.5)
subview.constraint.width(to: view)
subview.constraint.height(to: view, .width)
subview.constraint.height(to: view, multiplier: 0.5)
subview.constraint.width(constant: 50)
subview.constraint.height(constant: 75)
UIView
and UILayoutGuide
can be used interchangeably.
subview.constraint.edges(to: view.layoutMarginsGuide)
subview.constraint.lastBaseline(to: view.safeAreaLayoutGuide, .bottom)
subview.constraint.width(to: view.readableContentGuide)
Allmost all constraint methods have relation
parameter.
subview.constraint.leading(to: view, relation: .greaterThanOrEqual)
All constraint methods have priority
parameter.
subview.constraint.leading(to: view, priority: .defaultLow)
Constraints are created active by default. All constraint methods have active
parameter to opt out of this.
subview.constraint.leading(to: view, active: false)
- iOS 11.0+
- Swift 5.0+
github "vadimtrifonov/ConstraintProxy"