Skip to content

Instantly share code, notes, and snippets.

@NicholasTD07
Last active August 27, 2015 09:07
Show Gist options
  • Save NicholasTD07/64580cada00b950f3154 to your computer and use it in GitHub Desktop.
Save NicholasTD07/64580cada00b950f3154 to your computer and use it in GitHub Desktop.
Doing iOS UI in code with SnapKit
import UIKit
import SnapKit
class SomeViewController: UIViewController {
var addButton = UIButton()
var helloWorldLabel = UILabel()
override func viewDidLoad() {
let superView = view
let views = [
addButton,
helloWorldLabel,
]
views.map { superView.addSubview($0) }
addButton.snp_makeConstraints { (make) -> Void in
// Centered vertically + As wide as the super view
make.centerY.left.right.equalTo(superView)
}
helloWorldLabel.snp_makeConstraints { (make) -> Void in
// As wide as the super view
make.left.right.equalTo(superView)
// Put it on the top of addButton
make.bottom.equalTo(addButton.snp_top)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment