Skip to content

Commit dc01675

Browse files
committed
Adds minimumConstant and maximumConstant
1 parent e810709 commit dc01675

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

RelativeConstraints/MANRelativeConstraint.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
1515
@property (nonatomic, strong, nullable) IBOutlet UIView *parentView;
1616
@property (nonatomic, assign) IBInspectable CGFloat relationMultiplier;
1717
@property (nonatomic, assign) IBInspectable CGFloat additionalConstant;
18+
@property (nonatomic, assign) IBInspectable CGFloat minimumConstant;
19+
@property (nonatomic, assign) IBInspectable CGFloat maximumConstant;
1820

1921
- (void)setNeedsConstantUpdate;
2022

RelativeConstraints/MANRelativeConstraint.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ + (void)load
3131

3232
- (void)setDefaults
3333
{
34+
_minimumConstant = nanf(NULL);
35+
_maximumConstant = nanf(NULL);
3436
}
3537

3638
- (void)setParentView:(nullable UIView *)parentView
@@ -62,9 +64,31 @@ - (void)setAdditionalConstant:(CGFloat)additionalConstant
6264
[self setNeedsConstantUpdate];
6365
}
6466

67+
- (void)setMinimumConstant:(CGFloat)minimumConstant
68+
{
69+
_minimumConstant = minimumConstant;
70+
[self setNeedsConstantUpdate];
71+
}
72+
73+
- (void)setMaximumConstant:(CGFloat)maximumConstant
74+
{
75+
_maximumConstant = maximumConstant;
76+
[self setNeedsConstantUpdate];
77+
}
78+
6579
- (void)setNeedsConstantUpdate
6680
{
67-
self.constant = ([self updatedConstant] * self.relationMultiplier) + self.additionalConstant;
81+
CGFloat newConstant = ([self updatedConstant] * self.relationMultiplier) + self.additionalConstant;
82+
83+
if (!isnan(self.minimumConstant)) {
84+
newConstant = MAX(self.minimumConstant, newConstant);
85+
}
86+
87+
if (!isnan(self.maximumConstant)) {
88+
newConstant = MIN(self.maximumConstant, newConstant);
89+
}
90+
91+
self.constant = newConstant;
6892
}
6993

7094
- (CGFloat)updatedConstant

0 commit comments

Comments
 (0)