Skip to content

Instantly share code, notes, and snippets.

@Azuritul
Last active March 10, 2016 09:48
Show Gist options
  • Save Azuritul/f522a6cd3082a516dc62 to your computer and use it in GitHub Desktop.
Save Azuritul/f522a6cd3082a516dc62 to your computer and use it in GitHub Desktop.
Auto layout center element to super view
// 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