Created
August 22, 2016 18:13
-
-
Save davelyon/b9531b844653b72a1a6617b3fe60e063 to your computer and use it in GitHub Desktop.
NSLayoutConstraint+Priority.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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