Skip to content

Instantly share code, notes, and snippets.

@dasdom
Last active August 29, 2015 14:16
Show Gist options
  • Save dasdom/1cb4d36060c01521df35 to your computer and use it in GitHub Desktop.
Save dasdom/1cb4d36060c01521df35 to your computer and use it in GitHub Desktop.
A closure to reuse button creation code.
import UIKit
let makeButton = { (title: String) -> UIButton in
let button = UIButton.buttonWithType(.System) as UIButton
button.setTranslatesAutoresizingMaskIntoConstraints(false)
button.layer.cornerRadius = 5
button.layer.borderWidth = 1.0
button.layer.borderColor = UIColor.yellowColor().CGColor
button.setTitle(title, forState: .Normal)
return button
}
let workButton = makeButton(NSLocalizedString("Work", comment: "Start working button title"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment