Skip to content

Instantly share code, notes, and snippets.

@stephenparish
Last active December 26, 2015 04:39
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 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