Skip to content

Instantly share code, notes, and snippets.

@davelyon
Created August 22, 2016 18:13
Show Gist options
  • Save davelyon/b9531b844653b72a1a6617b3fe60e063 to your computer and use it in GitHub Desktop.
Save davelyon/b9531b844653b72a1a6617b3fe60e063 to your computer and use it in GitHub Desktop.
NSLayoutConstraint+Priority.swift
let superView = UIView()
let view = UIView()
//: Example:
let constraints = [
view.leadingAnchor.constraint(greaterThanOrEqualTo: superView.leadingAnchor, constant: 12),
superView.trailingAnchor.constraint(greaterThanOrEqualTo: view.trailingAnchor, constant: 12),
view.topAnchor.constraint(greaterThanOrEqualTo: superView.topAnchor, constant: 12),
superView.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor, constant: 12),
view.centerXAnchor.constraint(equalTo: superView.centerXAnchor).withPriority(.high),
view.centerXAnchor.constraint(equalTo: superView.centerXAnchor).withPriority(.high),
]
extension NSLayoutConstraint {
func withPriority(_ p: UILayoutPriority) -> Self {
self.priority = p
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment