Skip to content

Instantly share code, notes, and snippets.

@vahotm
Last active January 20, 2016 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vahotm/f2516749db637f7e6b12 to your computer and use it in GitHub Desktop.
Save vahotm/f2516749db637f7e6b12 to your computer and use it in GitHub Desktop.
Snippet for constraints in Visual Format Language, that center view vertically and horizontally in its superview.
// Vertical center in container
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[superview]-(<=1)-[view]"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:viewDict]];
// Horizontal center in container
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[superview]-(<=1)-[view]"
options:NSLayoutFormatAlignAllCenterX
metrics:nil
views:viewDict]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment