Skip to content

Instantly share code, notes, and snippets.

@pietrorea
Last active April 19, 2017 01:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietrorea/c9431bcf3e9ce33140db to your computer and use it in GitHub Desktop.
Save pietrorea/c9431bcf3e9ce33140db to your computer and use it in GitHub Desktop.
Autolayout: the equivalent of [subview setFrame:self.view.bounds];
UIView *autoLayoutView = [[UIView alloc] init];
autoLayoutView.backgroundColor = [UIColor redColor];
autoLayoutView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:autoLayoutView];
NSDictionary *views = NSDictionaryOfVariableBindings(autoLayoutView);
NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[autoLayoutView]|"
options:nil
metrics:nil
views:views];
NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[autoLayoutView]|"
options:nil
metrics:nil
views:views];
[self.view addConstraints:hConstraints];
[self.view addConstraints:vConstraints];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment