Created
December 15, 2016 14:04
-
-
Save buranmert/2ecb72e7dce3fdf4c77e2d1c4f219226 to your computer and use it in GitHub Desktop.
Autolayout helper
This file contains 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
- (void)ag_addSubview:(UIView *)subview withInsets:(UIEdgeInsets)insets { | |
[self addSubview:subview]; | |
[subview setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeTop withConstant:insets.top]; | |
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeBottom withConstant:insets.bottom]; | |
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeLeft withConstant:insets.left]; | |
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeRight withConstant:insets.right]; | |
} | |
- (BOOL)addConstraintFromSubview:(UIView *)subview forAttribute:(NSLayoutAttribute)attribute withConstant:(CGFloat)constantValue { | |
if (constantValue == AGIneffectiveConstantValue) { | |
return NO; | |
} | |
NSLayoutConstraint *constraint = [NSLayoutConstraint | |
constraintWithItem:self | |
attribute:attribute | |
relatedBy:NSLayoutRelationEqual | |
toItem:subview | |
attribute:attribute | |
multiplier:1.f | |
constant:constantValue]; | |
[self addConstraint:constraint]; | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment