Last active
March 10, 2016 09:48
-
-
Save Azuritul/f522a6cd3082a516dc62 to your computer and use it in GitHub Desktop.
Auto layout center element to super view
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
// Auto layout center element to super view | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]]; | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]]; | |
//Auto layout | |
//指定自己width height同高 | |
[self addConstraint:[NSLayoutConstraint constraintWithItem:self | |
attribute:NSLayoutAttributeHeight | |
relatedBy:NSLayoutRelationEqual | |
toItem:self | |
attribute:NSLayoutAttributeWidth | |
multiplier:1.0 | |
constant:0.0]]; | |
[self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:60]]; | |
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeHeight multiplier:1 constant:self.frame.size.height]]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment