Created
October 28, 2013 19:04
-
-
Save kgn/7202655 to your computer and use it in GitHub Desktop.
Handy Auto Layout
This file contains hidden or 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
CGFloat distance = 10; | |
// Center two views side-by-side | |
[parentItem addConstraint:[NSLayoutConstraint constraintWithItem:leftItem attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationLessThanOrEqual toItem:parentItem attribute:NSLayoutAttributeCenterX multiplier:1 constant:-distance]]; | |
[parentItem addConstraint:[NSLayoutConstraint constraintWithItem:rightItem attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationLessThanOrEqual toItem:parentItem attribute:NSLayoutAttributeCenterX multiplier:1 constant:distance]]; | |
// Center two views, one ontop of the other | |
[parentItem addConstraint:[NSLayoutConstraint constraintWithItem:topItem attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationLessThanOrEqual toItem:parentItem attribute:NSLayoutAttributeCenterY multiplier:1 constant:-distance]]; | |
[parentItem addConstraint:[NSLayoutConstraint constraintWithItem:bottomItem attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationLessThanOrEqual toItem:parentItem attribute:NSLayoutAttributeCenterY multiplier:1 constant:distance]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment