Skip to content

Instantly share code, notes, and snippets.

@jparishy
Created September 11, 2014 01:20
Show Gist options
  • Save jparishy/1eaca3e8bcc89e120e89 to your computer and use it in GitHub Desktop.
Save jparishy/1eaca3e8bcc89e120e89 to your computer and use it in GitHub Desktop.
Category on UIView for adding constraints for a subview that fills itself with specific insets
@implementation UIView (LECommonLayoutConstraints)
- (void)le_addContraintsForFilledView:(UIView *)view insets:(UIEdgeInsets)insets
{
NSDictionary *metrics = @{
@"left" : @(insets.left),
@"top" : @(insets.top),
@"right" : @(insets.right),
@"bottom" : @(insets.bottom)
};
NSDictionary *views = NSDictionaryOfVariableBindings(view);
NSArray *horizontal = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-left-[view]-right-|" options:kNilOptions metrics:metrics views:views];
NSArray *vertical = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-top-[view]-bottom-|" options:kNilOptions metrics:metrics views:views];
[self addConstraints:horizontal];
[self addConstraints:vertical];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment