Last active
August 29, 2015 14:20
-
-
Save robertjpayne/29016d1af4730d2371b1 to your computer and use it in GitHub Desktop.
SnapKit Constraint Sheets
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
@loginViewController { | |
@formView { | |
width == ^ - 32.0 | |
centerX == ^ | |
centerY == ^ + 16.0 | |
bottom <= ^ - 16.0 | |
@emailField { | |
top.left.right == ^ | |
height == 44.0 | |
} | |
@emailPasswordSeparator { | |
top == @emailField.bottom | |
left.right == ^ | |
height == 0.5 | |
} | |
@passwordField { | |
top == @emailPasswordSeparator.bottom | |
left.right.bottom == ^ | |
height == 44.0 | |
} | |
} | |
@submit-button { | |
width == ^ - 32.0 | |
top == @formView.bottom + 16.0 | |
} | |
} |
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
self.formView.snp_makeConstraints { (make) -> Void in | |
make.width.equalTo(self.view).offset(-32.0) | |
make.centerX.equalTo(self.view) | |
make.centerY.equalTo(self.view).offset(16.0) | |
make.bottom.lessThanOrEqualTo(self.view).offset(-16.0) | |
} | |
self.emailField.snp_makeConstraints { (make) -> Void in | |
make.top.left.right.equalTo(self.formView) | |
make.height.equalTo(44.0) | |
} | |
self.emailPasswordSeparator.snp_makeConstraints { (make) -> Void in | |
make.top.equalTo(self.emailField.snp_bottom) | |
make.left.right.equalTo(self.formView) | |
make.height.equalTo(0.5) | |
} | |
self.passwordField.snp_makeConstraints { (make) -> Void in | |
make.top.equalTo(self.emailPasswordSeparator.snp_bottom) | |
make.bottom.left.right.equalTo(self.formView) | |
make.height.equalTo(44.0) | |
} | |
self.submitButton.snp_makeConstraints { (make) -> Void in | |
make.width.equalTo(self.formView).offset(-32.0) | |
make.top.equalTo(self.formView.snp_bottom).offset(16.0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a very early proposal for constraint style sheets for iOS Auto Layout. The main goal is to allow external files to define constraints and be reloaded whenever they are saved.
The idea is that you 'tag' each view:
You would then override
updateViewConstraints
orupdateConstraints
: