Last active
August 27, 2015 09:07
-
-
Save NicholasTD07/64580cada00b950f3154 to your computer and use it in GitHub Desktop.
Doing iOS UI in code with SnapKit
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
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