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/6504515 to your computer and use it in GitHub Desktop.

Select an option

Save charlesmchen/6504515 to your computer and use it in GitHub Desktop.
UIButton *button = ...;
UIView *superview = ...;
NSDictionary *variableMap = NSDictionaryOfVariableBindings(label, superview);
NSLayoutConstraint *cn = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[button]-12-[superview]"
options:0
metrics:nil
views:variableMap];
[superview addConstraint:cn];
cn = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[superview]-(<=1)-[button]"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:variableMap];
[superview addConstraint:cn];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment