Last active
April 19, 2017 01:44
-
-
Save pietrorea/c9431bcf3e9ce33140db to your computer and use it in GitHub Desktop.
Autolayout: the equivalent of [subview setFrame:self.view.bounds];
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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