Created
November 7, 2014 16:22
-
-
Save preble/b819c22f6de4d68a5606 to your computer and use it in GitHub Desktop.
NSView extension: insetSubview(_:dx:dy:)
This file contains hidden or 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 NSView { | |
func insetSubview(subview: NSView, dx: CGFloat, dy: CGFloat) { | |
addSubview(subview) | |
subview.translatesAutoresizingMaskIntoConstraints = false | |
let constrain = { (attribute: NSLayoutAttribute, constant: CGFloat) in | |
subview.addConstraint(NSLayoutConstraint( | |
item: subview, | |
attribute: attribute, | |
relatedBy: .Equal, | |
toItem: self, | |
attribute: attribute, | |
multiplier: 1.0, | |
constant: constant)) | |
} | |
constrain(.Left, dx) | |
constrain(.Right, dx) | |
constrain(.Top, dy) | |
constrain(.Bottom, dy) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment