Skip to content

Instantly share code, notes, and snippets.

@charlesmchen
Last active December 22, 2015 17:09
Show Gist options
  • Select an option

  • Save charlesmchen/6504510 to your computer and use it in GitHub Desktop.

Select an option

Save charlesmchen/6504510 to your computer and use it in GitHub Desktop.
UIButton *button = ...;
UIView *superview = ...;
NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:button
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0];
[superview addConstraint:cn];
cn = [NSLayoutConstraint constraintWithItem:button
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:-20.0];
[superview addConstraint:cn];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment