Created
August 18, 2015 16:11
-
-
Save dutran90/ef413e2608fd9489af3c to your computer and use it in GitHub Desktop.
Autolayout Programming
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
// Width constraint, half of parent view width | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerView | |
attribute:NSLayoutAttributeWidth | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeWidth | |
multiplier:0.5 | |
constant:0]]; | |
// Height constraint, half of parent view height | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerView | |
attribute:NSLayoutAttributeHeight | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeHeight | |
multiplier:0.5 | |
constant:0]]; | |
// Center horizontally | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerView | |
attribute:NSLayoutAttributeCenterX | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeCenterX | |
multiplier:1.0 | |
constant:0.0]]; | |
// Center vertically | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerView | |
attribute:NSLayoutAttributeCenterY | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeCenterY | |
multiplier:1.0 | |
constant:0.0]]; | |
// NSLayoutAttributeLeading | |
// NSLayoutAttributeTrailing | |
// NSLayoutAttributeTop | |
// NSLayoutAttributeBottom | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment