Skip to content

Instantly share code, notes, and snippets.

@stephenparish
Last active December 26, 2015 04:39
Show Gist options
  • Save stephenparish/7094561 to your computer and use it in GitHub Desktop.
Save stephenparish/7094561 to your computer and use it in GitHub Desktop.
Using auto layout with a child UIViewController
#import "SPAutoLayoutChildViewController.h"
@implementation SPAutoLayoutChildViewController
- (void)updateViewConstraints {
if (self.view.superview) {
UIView *thisView = self.view;
thisView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *views = NSDictionaryOfVariableBindings(thisView);
[self.view.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[thisView]|" options:0 metrics:nil views:views]];
[self.view.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[thisView]|" options:0 metrics:nil views:views]];
}
[super updateViewConstraints];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment