Skip to content

Instantly share code, notes, and snippets.

@th3m477
Created August 2, 2019 07:35
Show Gist options
  • Save th3m477/95355948cfec064084b65b06c0c2cd6d to your computer and use it in GitHub Desktop.
Save th3m477/95355948cfec064084b65b06c0c2cd6d to your computer and use it in GitHub Desktop.
Constraint shortcuts
extension NSLayoutAnchor {
@objc @discardableResult func eq(_ anchor: NSLayoutAnchor, _ constant: CGFloat = 0.0) -> NSLayoutConstraint {
let c = constraint(equalTo: anchor, constant: constant)
c.isActive = true
return c
}
@objc @discardableResult func lte(_ anchor: NSLayoutAnchor, _ constant: CGFloat = 0.0) -> NSLayoutConstraint {
let c = constraint(lessThanOrEqualTo: anchor, constant: constant)
c.isActive = true
return c
}
@objc @discardableResult func gte(_ anchor: NSLayoutAnchor, _ constant: CGFloat = 0.0) -> NSLayoutConstraint {
let c = constraint(greaterThanOrEqualTo: anchor, constant: constant)
c.isActive = true
return c
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment