From dade6659b90f9daa8a3098f20f5ebf86a9dfe2ee Mon Sep 17 00:00:00 2001 From: iwill <minglq.9@gmail.com> Date: Sat, 15 Oct 2016 11:19:13 +0800 Subject: [PATCH] Added inset property --- Masonry/MASCompositeConstraint.m | 6 ++++++ Masonry/MASConstraint.h | 14 ++++++++++++++ Masonry/MASConstraint.m | 9 +++++++++ Masonry/MASViewConstraint.m | 4 ++++ 4 files changed, 33 insertions(+), 0 deletions(-) diff --git a/Masonry/MASCompositeConstraint.m b/Masonry/MASCompositeConstraint.m index ed63ed6..2002a40 100644 --- a/Masonry/MASCompositeConstraint.m +++ b/Masonry/MASCompositeConstraint.m @@ -129,6 +129,12 @@ } } +- (void)setInset:(CGFloat)inset { + for (MASConstraint *constraint in self.childConstraints) { + constraint.inset = inset; + } +} + - (void)setOffset:(CGFloat)offset { for (MASConstraint *constraint in self.childConstraints) { constraint.offset = offset; diff --git a/Masonry/MASConstraint.h b/Masonry/MASConstraint.h index 70a10c8..8057a10 100644 --- a/Masonry/MASConstraint.h +++ b/Masonry/MASConstraint.h @@ -27,6 +27,13 @@ /** * Modifies the NSLayoutConstraint constant, * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following + * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight + */ +- (MASConstraint * (^)(CGFloat inset))inset; + +/** + * Modifies the NSLayoutConstraint constant, + * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following * NSLayoutAttributeWidth, NSLayoutAttributeHeight */ - (MASConstraint * (^)(CGSize offset))sizeOffset; @@ -166,6 +173,13 @@ /** * Modifies the NSLayoutConstraint constant, * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following + * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight + */ +- (void)setInset:(CGFloat)inset; + +/** + * Modifies the NSLayoutConstraint constant, + * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following * NSLayoutAttributeWidth, NSLayoutAttributeHeight */ - (void)setSizeOffset:(CGSize)sizeOffset; diff --git a/Masonry/MASConstraint.m b/Masonry/MASConstraint.m index f24ec10..2af737d 100644 --- a/Masonry/MASConstraint.m +++ b/Masonry/MASConstraint.m @@ -92,6 +92,13 @@ }; } +- (MASConstraint * (^)(CGFloat))inset { + return ^id(CGFloat inset){ + self.inset = inset; + return self; + }; +} + - (MASConstraint * (^)(CGSize))sizeOffset { return ^id(CGSize offset) { self.sizeOffset = offset; @@ -269,6 +276,8 @@ - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); } +- (void)setInset:(CGFloat __unused)inset { MASMethodNotImplemented(); } + - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); } - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); } diff --git a/Masonry/MASViewConstraint.m b/Masonry/MASViewConstraint.m index 84a801e..e110e3e 100644 --- a/Masonry/MASViewConstraint.m +++ b/Masonry/MASViewConstraint.m @@ -254,6 +254,10 @@ static char kInstalledConstraintsKey; } } +- (void)setInset:(CGFloat)inset { + [self setInsets:(MASEdgeInsets){.top = inset, .left = inset, .bottom = inset, .right = inset}]; +} + - (void)setOffset:(CGFloat)offset { self.layoutConstant = offset; } -- libgit2 0.24.0