Authored by Jonas Budelmann

renaming: sides to edges, constraints to constrain

... ... @@ -10,7 +10,7 @@
#import "MASConstraint.h"
typedef NS_ENUM(NSInteger, MASCompositeViewConstraintType) {
MASCompositeViewConstraintTypeSides,
MASCompositeViewConstraintTypeEdges,
MASCompositeViewConstraintTypeSize,
MASCompositeViewConstraintTypeCenter,
};
... ...
... ... @@ -37,7 +37,7 @@
NSArray *viewAttributes;
switch (self.type) {
case MASCompositeViewConstraintTypeSides:
case MASCompositeViewConstraintTypeEdges:
viewAttributes = @[
self.view.mas_left, self.view.mas_top,
self.view.mas_bottom, self.view.mas_right
... ...
... ... @@ -23,7 +23,7 @@
@property (nonatomic, strong, readonly) id<MASConstraint> centerY;
@property (nonatomic, strong, readonly) id<MASConstraint> baseline;
@property (nonatomic, strong, readonly) id<MASConstraint> sides;
@property (nonatomic, strong, readonly) id<MASConstraint> edges;
@property (nonatomic, strong, readonly) id<MASConstraint> size;
@property (nonatomic, strong, readonly) id<MASConstraint> center;
... ...
... ... @@ -101,8 +101,8 @@
#pragma mark - composite Attributes
- (id<MASConstraint>)sides {
MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithView:self.view type:MASCompositeViewConstraintTypeSides];
- (id<MASConstraint>)edges {
MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithView:self.view type:MASCompositeViewConstraintTypeEdges];
constraint.delegate = self;
return constraint;
}
... ...
... ... @@ -24,6 +24,6 @@
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *constraints))block;
- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *constrain))block;
@end
\ No newline at end of file
... ...
... ... @@ -10,11 +10,11 @@
@implementation UIView (MASAdditions)
- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *constraints))block {
- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *))block {
self.translatesAutoresizingMaskIntoConstraints = NO;
MASConstraintBuilder *viewConstraintBuilder = [[MASConstraintBuilder alloc] initWithView:self];
block(viewConstraintBuilder);
[viewConstraintBuilder commit];
MASConstraintBuilder *constraintBuilder = [[MASConstraintBuilder alloc] initWithView:self];
block(constraintBuilder);
[constraintBuilder commit];
}
#pragma mark - attribute properties
... ...
... ... @@ -48,7 +48,7 @@ MAS_ATTR_FORWARD(centerX);
MAS_ATTR_FORWARD(centerY);
MAS_ATTR_FORWARD(baseline);
- (void)buildConstraints:(void(^)(MASConstraintBuilder *constraints))block {
- (void)buildConstraints:(void(^)(MASConstraintBuilder *))block {
[self mas_buildConstraints:block];
}
... ...
... ... @@ -45,38 +45,38 @@
self.animatableConstraints = NSMutableArray.new;
[view1 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
[view1 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
[self.animatableConstraints addObjectsFromArray:@[
constraints.sides.equal(superview).insets(paddingInsets).priorityLow(),
constraints.bottom.equal(view3.mas_top).offset(-padding),
constraints.right.equal(view2.mas_left).offset(-padding),
]];
constrain.edges.equal(superview).insets(paddingInsets).priorityLow(),
constrain.bottom.equal(view3.mas_top).offset(-padding),
constrain.right.equal(view2.mas_left).offset(-padding),
]];
constraints.size.equal(view2);
constraints.height.equal(view3.mas_height);
constrain.size.equal(view2);
constrain.height.equal(view3.mas_height);
}];
[view2 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
[view2 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
[self.animatableConstraints addObjectsFromArray:@[
constraints.sides.equal(superview).insets(paddingInsets).priorityLow(),
constraints.left.equal(view1.mas_right).offset(padding),
constraints.bottom.equal(view3.mas_top).offset(-padding),
]];
constrain.edges.equal(superview).insets(paddingInsets).priorityLow(),
constrain.left.equal(view1.mas_right).offset(padding),
constrain.bottom.equal(view3.mas_top).offset(-padding),
]];
constraints.size.equal(view1);
constraints.height.equal(view3.mas_height);
constrain.size.equal(view1);
constrain.height.equal(view3.mas_height);
}];
[view3 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
[view3 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
[self.animatableConstraints addObjectsFromArray:@[
constraints.sides.equal(superview).insets(paddingInsets).priorityLow(),
constraints.top.equal(view1.mas_bottom).offset(padding),
]];
constrain.edges.equal(superview).insets(paddingInsets).priorityLow(),
constrain.top.equal(view1.mas_bottom).offset(padding),
]];
//TODO or pass an array
//constraints.height.equal(superview.subviews);
constraints.height.equal(view1.mas_height);
constraints.height.equal(view2.mas_height);
constrain.height.equal(view1.mas_height);
constrain.height.equal(view2.mas_height);
}];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapWithGestureRecognizer:)];
... ...
... ... @@ -35,41 +35,41 @@
UIView *superview = self;
int padding = 10;
[view1 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
constraints.top.equal(superview.mas_top).offset(padding);
constraints.left.equal(superview.mas_left).offset(padding);
constraints.bottom.equal(view3.mas_top).offset(-padding);
constraints.right.equal(view2.mas_left).offset(-padding);
constraints.width.equal(view2.mas_width);
[view1 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
constrain.top.greaterThanOrEqual(superview.mas_top).offset(padding);
constrain.left.equal(superview.mas_left).offset(padding);
constrain.bottom.equal(view3.mas_top).offset(-padding);
constrain.right.equal(view2.mas_left).offset(-padding);
constrain.width.equal(view2.mas_width);
//you can chain same attribute
constraints.height
constrain.height
.equal(view2.mas_height)
.equal(view3.mas_height);
}];
[view2 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
constraints.top.equal(superview.mas_top).offset(padding);
constraints.left.equal(view1.mas_right).offset(padding);
constraints.bottom.equal(view3.mas_top).offset(-padding);
constraints.right.equal(superview.mas_right).offset(-padding);
constraints.width.equal(view1.mas_width);
[view2 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
constrain.top.equal(superview.mas_top).offset(padding);
constrain.left.equal(view1.mas_right).offset(padding);
constrain.bottom.equal(view3.mas_top).offset(-padding);
constrain.right.equal(superview.mas_right).offset(-padding);
constrain.width.equal(view1.mas_width);
//or define it multiple times
constraints.height.equal(view1.mas_height);
constraints.height.equal(view3.mas_height);
constrain.height.equal(view1.mas_height);
constrain.height.equal(view3.mas_height);
}];
[view3 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
constraints.top.equal(view1.mas_bottom).offset(padding);
constraints.left.equal(superview.mas_left).offset(padding);
constraints.bottom.equal(superview.mas_bottom).offset(-padding);
constraints.right.equal(superview.mas_right).offset(-padding);
[view3 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
constrain.top.equal(view1.mas_bottom).offset(padding);
constrain.left.equal(superview.mas_left).offset(padding);
constrain.bottom.equal(superview.mas_bottom).offset(-padding);
constrain.right.equal(superview.mas_right).offset(-padding);
//TODO or pass an array
//constraints.height.equal(superview.subviews);
constraints.height.equal(view1.mas_height);
constraints.height.equal(view2.mas_height);
constrain.height.equal(view1.mas_height);
constrain.height.equal(view2.mas_height);
}];
return self;
... ...
... ... @@ -28,18 +28,18 @@
//example of using constants
[view1 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
constraints.top.equal(@20);
constraints.left.equal(@20);
constraints.bottom.equal(@-20);
constraints.right.equal(@-20);
[view1 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
constrain.top.equal(@20);
constrain.left.equal(@20);
constrain.bottom.equal(@-20);
constrain.right.equal(@-20);
}];
[view2 mas_buildConstraints:^(MASConstraintBuilder *constraints) {
constraints.centerY.equal(@50);
constraints.centerX.equal(@0);
constraints.width.equal(@200);
constraints.height.equal(@100);
[view2 mas_buildConstraints:^(MASConstraintBuilder *constrain) {
constrain.centerY.equal(@50);
constrain.centerX.equal(@0);
constrain.width.equal(@200);
constrain.height.equal(@100);
}];
return self;
... ...
... ... @@ -22,8 +22,8 @@
view.layer.borderWidth = 2;
[self addSubview:view];
[view mas_buildConstraints:^(MASConstraintBuilder *constraints) {
constraints.sides.equal(lastView).insets(UIEdgeInsetsMake(5, 10, 15, 20));
[view mas_buildConstraints:^(MASConstraintBuilder *constrain) {
constrain.edges.equal(lastView).insets(UIEdgeInsetsMake(5, 10, 15, 20));
}];
lastView = view;
... ...