Created
September 11, 2014 01:20
-
-
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
This file contains hidden or 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
@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