Skip to content

Instantly share code, notes, and snippets.

@samdmarshall
Created February 18, 2014 19:40
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 samdmarshall/9078370 to your computer and use it in GitHub Desktop.
Save samdmarshall/9078370 to your computer and use it in GitHub Desktop.
@implementation NSView(Additions)
- (void)addSubviewAndUpdateConstraints:(NSView *)view {
[self addSubview:view];
view.translatesAutoresizingMaskIntoConstraints = NO;
for (NSString *string in @[@"H:|[view]|", @"V:|[view]|"]) {
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:string options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)];
[view.superview addConstraints:constraints];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment