Skip to content

Instantly share code, notes, and snippets.

@berkcebi
Last active March 15, 2017 18:31
Show Gist options
  • Save berkcebi/d6d76e0e6b6103149e8897f7d8a72bfa to your computer and use it in GitHub Desktop.
Save berkcebi/d6d76e0e6b6103149e8897f7d8a72bfa to your computer and use it in GitHub Desktop.
Nib-free layout code sample
// Defining the appearance while creating the property.
let editButton: NSButton = {
let button = NSButton()
button.bordered = false
button.setButtonType(.MomentaryChange)
button.image = NSImage(named: "icEdit")
button.alternateImage = NSImage(named: "icEditSelected")
return button
}()
// Declaring Auto Layout constraints with Cartography.
constrain(view, editButton, self) { view, editButton, superview in
editButton.left == view.right
editButton.right <= superview.right - View.margin
editButton.centerY == view.centerY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment