Last active
February 4, 2021 15:29
-
-
Save jtbandes/6959f4f0b80e4cf7d0a0 to your computer and use it in GitHub Desktop.
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
// Would you rather use this: | |
NSLayoutConstraint(item: label, attribute: .Leading, relatedBy: .Equal, toItem: button, attribute: .Trailing, multiplier: 1, constant: 0).active = true | |
// or this? | |
label.constrain(.Leading, .Equal, to: button, .Trailing, plus: 20) | |
public extension NSView | |
{ | |
func constrain( | |
attribute: NSLayoutAttribute, | |
_ relation: NSLayoutRelation, | |
to otherView: NSView, | |
_ otherAttribute: NSLayoutAttribute, | |
times multiplier: CGFloat = 1, | |
plus constant: CGFloat = 0 | |
atPriority priority: NSLayoutPriority = 1000) -> NSLayoutConstraint | |
{ | |
let c = NSLayoutConstraint( | |
item: self, | |
attribute: attribute, | |
relatedBy: relation, | |
toItem: otherView, | |
attribute: otherAttribute, | |
multiplier: multiplier, | |
constant: constant) | |
c.priority = priority | |
c.active = true | |
return c | |
} | |
} |
If you like this, check these out:
https://github.com/robb/Cartography
https://github.com/Rightpoint/Anchorage
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesomeeee