Authored by Jonas Budelmann

better header comments, weak ref to views!

... ... @@ -79,7 +79,6 @@
DD52F1E6179CAACA005CD195 /* UIView+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+MASAdditions.m"; sourceTree = "<group>"; };
DD52F1ED179CAAEE005CD195 /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = "<group>"; };
DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MASShorthandAdditions.h"; sourceTree = "<group>"; };
DDF3875D179E8A2900178773 /* SpecHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpecHelpers.h; sourceTree = "<group>"; };
DE643A835A4447F4807FDBFA /* libPods-MasonryTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MasonryTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
... ... @@ -179,7 +178,6 @@
DD52F1D7179CAA78005CD195 /* Specs */ = {
isa = PBXGroup;
children = (
DDF3875D179E8A2900178773 /* SpecHelpers.h */,
DD52F1D8179CAA9C005CD195 /* MASCompositeConstraintSpec.m */,
DD52F1D9179CAA9C005CD195 /* MASViewConstraintSpec.m */,
);
... ...
... ... @@ -10,15 +10,15 @@
#import "MASConstraint.h"
typedef NS_ENUM(NSInteger, MASCompositeViewConstraintType) {
MASCompositeViewConstraintTypeEdges,
MASCompositeViewConstraintTypeSize,
MASCompositeViewConstraintTypeCenter,
MASCompositeViewConstraintTypeEdges, //top, left, bottom, right
MASCompositeViewConstraintTypeSize, //width, height
MASCompositeViewConstraintTypeCenter, //centerX, centerY
};
@interface MASCompositeConstraint : NSObject <MASConstraint>
@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
@property (nonatomic, strong, readonly) UIView *view;
@property (nonatomic, weak, readonly) UIView *view;
@property (nonatomic, assign, readonly) MASCompositeViewConstraintType type;
- (id)initWithView:(UIView *)view type:(MASCompositeViewConstraintType)type;
... ...
... ... @@ -69,7 +69,7 @@
[self.completedChildConstraints addObject:constraint];
}
#pragma mark - layout constant
#pragma mark - NSLayoutConstraint constant proxies
- (id<MASConstraint> (^)(UIEdgeInsets))insets {
return ^id(UIEdgeInsets insets) {
... ... @@ -107,7 +107,7 @@
};
}
#pragma mark - layout multiplier
#pragma mark - NSLayoutConstraint multiplier proxies
- (id<MASConstraint> (^)(CGFloat))percent {
return ^id(CGFloat percent) {
... ... @@ -118,7 +118,7 @@
};
}
#pragma mark - layout priority
#pragma mark - MASLayoutPriority proxies
- (id<MASConstraint> (^)(MASLayoutPriority))priority {
return ^id(MASLayoutPriority priority) {
... ... @@ -150,7 +150,7 @@
};
}
#pragma mark - layout relation
#pragma mark - NSLayoutRelation proxies
- (id<MASConstraint> (^)(id))relationWithBlock:(id<MASConstraint> (^)(id<MASConstraint> constraint, id attr))block {
return ^id(id attr) {
... ... @@ -199,6 +199,8 @@
for (id<MASConstraint> constraint in self.completedChildConstraints) {
[constraint commit];
}
[self.currentChildConstraints removeAllObjects];
[self.completedChildConstraints removeAllObjects];
}
@end
... ...
... ... @@ -19,22 +19,22 @@ typedef float MASLayoutPriority;
@protocol MASConstraint <NSObject>
//layout constants
//NSLayoutConstraint constant proxies
@property (nonatomic, copy, readonly) id<MASConstraint> (^insets)(UIEdgeInsets insets);
@property (nonatomic, copy, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset);
@property (nonatomic, copy, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset);
@property (nonatomic, copy, readonly) id<MASConstraint> (^offset)(CGFloat offset);
//layout multipliers
//NSLayoutConstraint multiplier proxies
@property (nonatomic, copy, readonly) id<MASConstraint> (^percent)(CGFloat percent);
//layout priority
@property (nonatomic, copy, readonly) id<MASConstraint> (^priority)(UILayoutPriority priority);
//MASLayoutPriority proxies
@property (nonatomic, copy, readonly) id<MASConstraint> (^priority)(MASLayoutPriority priority);
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityLow)();
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityMedium)();
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityHigh)();
//layout relation
//NSLayoutRelation proxies
@property (nonatomic, copy, readonly) id<MASConstraint> (^equalTo)(id attr);
@property (nonatomic, copy, readonly) id<MASConstraint> (^greaterThanOrEqualTo)(id attr);
@property (nonatomic, copy, readonly) id<MASConstraint> (^lessThanOrEqualTo)(id attr);
... ... @@ -42,12 +42,18 @@ typedef float MASLayoutPriority;
//semantic properties
@property (nonatomic, copy, readonly) id<MASConstraint> with;
/**
Creates a NSLayoutConstraint. The constraint is added to the first view or the or the closest common superview of the first and second view.
*/
- (void)commit;
@end
@protocol MASConstraintDelegate <NSObject>
/**
Notifies the delegate when the constraint is has the minimum set of properties, has a NSLayoutRelation and view
*/
- (void)addConstraint:(id<MASConstraint>)constraint;
@end
\ No newline at end of file
... ...
... ... @@ -13,7 +13,7 @@
@interface MASConstraintMaker () <MASConstraintDelegate>
@property (nonatomic, strong) UIView *view;
@property (nonatomic, weak) UIView *view;
@property (nonatomic, strong) NSMutableArray *constraints;
@end
... ...
... ... @@ -10,11 +10,16 @@
@interface MASViewAttribute : NSObject
@property (nonatomic, strong, readonly) UIView *view;
@property (nonatomic, weak, readonly) UIView *view;
@property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute;
- (id)initWithView:(UIView *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute;
- (BOOL)isAlignment;
/**
Creates a MASConstraintMaker with the callee view. any constraints defined are added to the view or the appropriate superview once the block has finished executing
@return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight
*/
- (BOOL)isSizeAttribute;
@end
... ...
... ... @@ -20,8 +20,8 @@
return self;
}
- (BOOL)isAlignment {
return self.layoutAttribute != NSLayoutAttributeWidth && self.layoutAttribute != NSLayoutAttributeHeight;
- (BOOL)isSizeAttribute {
return self.layoutAttribute == NSLayoutAttributeWidth || self.layoutAttribute == NSLayoutAttributeHeight;
}
@end
... ...
... ... @@ -61,7 +61,6 @@
} else {
NSAssert(YES, @"attempting to add unsupported attribute: %@", secondViewAttribute);
}
[self.delegate addConstraint:self];
}
- (instancetype)cloneIfNeeded {
... ... @@ -76,7 +75,7 @@
return self;
}
#pragma mark - layout constant
#pragma mark - NSLayoutConstraint constant proxies
- (id<MASConstraint> (^)(UIEdgeInsets))insets {
return ^id(UIEdgeInsets insets){
... ... @@ -142,7 +141,7 @@
};
}
#pragma mark - layout multiplier
#pragma mark - NSLayoutConstraint multiplier proxies
- (id<MASConstraint> (^)(CGFloat))percent {
return ^id(CGFloat percent) {
... ... @@ -154,7 +153,7 @@
};
}
#pragma mark - layout priority
#pragma mark - MASLayoutPriority proxies
- (id<MASConstraint> (^)(MASLayoutPriority))priority {
return ^id(MASLayoutPriority priority) {
... ... @@ -187,7 +186,7 @@
};
}
#pragma mark - layout relation
#pragma mark - NSLayoutRelation proxies
- (id<MASConstraint> (^)(id))equalTo {
return ^id(id attr) {
... ... @@ -197,6 +196,7 @@
MASViewConstraint *viewConstraint = [self cloneIfNeeded];
viewConstraint.layoutRelation = NSLayoutRelationEqual;
viewConstraint.secondViewAttribute = attr;
[viewConstraint.delegate addConstraint:viewConstraint];
return viewConstraint;
};
}
... ... @@ -209,6 +209,7 @@
MASViewConstraint *viewConstraint = [self cloneIfNeeded];
viewConstraint.layoutRelation = NSLayoutRelationGreaterThanOrEqual;
viewConstraint.secondViewAttribute = attr;
[viewConstraint.delegate addConstraint:viewConstraint];
return viewConstraint;
};
}
... ... @@ -221,6 +222,7 @@
MASViewConstraint *viewConstraint = [self cloneIfNeeded];
viewConstraint.layoutRelation = NSLayoutRelationLessThanOrEqual;
viewConstraint.secondViewAttribute = attr;
[viewConstraint.delegate addConstraint:viewConstraint];
return viewConstraint;
};
}
... ... @@ -240,7 +242,7 @@
NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute;
UIView *secondLayoutItem = self.secondViewAttribute.view;
NSLayoutAttribute secondLayoutAttribute = self.secondViewAttribute.layoutAttribute;
if (self.firstViewAttribute.isAlignment && !self.secondViewAttribute) {
if (!self.firstViewAttribute.isSizeAttribute && !self.secondViewAttribute) {
secondLayoutItem = firstLayoutItem.superview;
secondLayoutAttribute = firstLayoutAttribute;
}
... ...
... ... @@ -12,6 +12,7 @@
@interface UIView (MASAdditions)
// following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute
@property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
... ... @@ -24,6 +25,11 @@
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
/**
Creates a MASConstraintMaker with the callee view. any constraints defined are added to the view or the appropriate superview once the block has finished executing
@param block scope within which you can build up the constraints which you wish to apply to the view.
*/
- (void)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
@end
\ No newline at end of file
... ...
... ... @@ -17,7 +17,7 @@
[constraintMaker commit];
}
#pragma mark - attribute properties
#pragma mark - NSLayoutAttribute properties
- (MASViewAttribute *)mas_left {
return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft];
... ...
... ... @@ -8,7 +8,6 @@
#import "MASCompositeConstraint.h"
#import "MASViewConstraint.h"
#import "SpecHelpers.h"
@interface MASCompositeConstraint () <MASConstraintDelegate>
... ... @@ -26,8 +25,22 @@
SpecBegin(MASCompositeConstraint)
__block id<MASConstraintDelegate> delegate;
__block UIView *superview;
__block UIView *view;
__block MASCompositeConstraint *composite;
beforeEach(^{
composite = nil;
delegate = mockProtocol(@protocol(MASConstraintDelegate));
view = UIView.new;
superview = UIView.new;
[superview addSubview:view];
});
it(@"should create centerY and centerX children", ^{
MASCompositeConstraint *composite = createCompositeWithType(MASCompositeViewConstraintTypeCenter);
composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeViewConstraintTypeCenter];
expect(composite.currentChildConstraints).to.haveCountOf(2);
MASViewConstraint *viewConstraint = composite.currentChildConstraints[0];
... ... @@ -41,7 +54,7 @@ it(@"should create centerY and centerX children", ^{
it(@"should create top, left, bottom, right children", ^{
UIView *newView = UIView.new;
MASCompositeConstraint *composite = createCompositeWithType(MASCompositeViewConstraintTypeEdges);
composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeViewConstraintTypeEdges];
composite.equalTo(newView);
expect(composite.completedChildConstraints).to.haveCountOf(4);
... ... @@ -68,7 +81,7 @@ it(@"should create top, left, bottom, right children", ^{
});
it(@"should create width and height children", ^{
MASCompositeConstraint *composite = createCompositeWithType(MASCompositeViewConstraintTypeSize);
composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeViewConstraintTypeSize];
expect(composite.currentChildConstraints).to.haveCountOf(2);
MASViewConstraint *viewConstraint = composite.currentChildConstraints[0];
... ... @@ -81,24 +94,25 @@ it(@"should create width and height children", ^{
});
it(@"should complete children", ^{
UIView *view = UIView.new;
MASCompositeConstraint *composite = createCompositeWithType(MASCompositeViewConstraintTypeSize);
composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeViewConstraintTypeSize];
composite.delegate = delegate;
UIView *newView = UIView.new;
//first equality statement
composite.equalTo(view).sizeOffset(CGSizeMake(90, 30));
composite.equalTo(newView).sizeOffset(CGSizeMake(90, 30));
[verify(composite.delegate) addConstraint:(id)composite];
[verify(delegate) addConstraint:(id)composite];
expect(composite.completedChildConstraints).to.haveCountOf(2);
expect(composite.currentChildConstraints).to.haveCountOf(2);
MASViewConstraint *viewConstraint = composite.completedChildConstraints[0];
expect(viewConstraint.secondViewAttribute.view).to.beIdenticalTo(view);
expect(viewConstraint.secondViewAttribute.view).to.beIdenticalTo(newView);
expect(viewConstraint.secondViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeWidth);
expect(viewConstraint.layoutConstant).to.equal(90);
viewConstraint = composite.completedChildConstraints[1];
expect(viewConstraint.secondViewAttribute.view).to.beIdenticalTo(view);
expect(viewConstraint.secondViewAttribute.view).to.beIdenticalTo(newView);
expect(viewConstraint.secondViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeHeight);
expect(viewConstraint.layoutConstant).to.equal(30);
... ... @@ -127,4 +141,24 @@ it(@"should complete children", ^{
expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeHeight);
});
it(@"should remove all on commit", ^{
composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeViewConstraintTypeSize];
composite.delegate = delegate;
UIView *newView = UIView.new;
[superview addSubview:newView];
//first equality statement
composite.equalTo(newView).sizeOffset(CGSizeMake(90, 30));
[verify(delegate) addConstraint:(id)composite];
expect(composite.completedChildConstraints).to.haveCountOf(2);
expect(composite.currentChildConstraints).to.haveCountOf(2);
[composite commit];
expect(composite.completedChildConstraints).to.haveCountOf(0);
expect(composite.currentChildConstraints).to.haveCountOf(0);
});
SpecEnd
\ No newline at end of file
... ...
... ... @@ -8,7 +8,7 @@
#import "MASViewConstraint.h"
#import "MASConstraint.h"
#import "SpecHelpers.h"
#import "UIView+MASAdditions.h"
@interface MASViewConstraint ()
... ... @@ -23,22 +23,30 @@
SpecBegin(MASViewConstraint)
__block id<MASConstraintDelegate> delegate;
__block UIView *superview;
__block MASViewConstraint *constraint;
__block MASViewAttribute *secondViewAttribute;
__block UIView *otherView;
beforeEach(^{
superview = UIView.new;
constraint = createConstraintWithLayoutAttribute(NSLayoutAttributeWidth);
[superview addSubview:constraint.firstViewAttribute.view];
delegate = mockProtocol(@protocol(MASConstraintDelegate));
UIView *view = UIView.new;
constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_width];
constraint.delegate = delegate;
[superview addSubview:view];
secondViewAttribute = createViewAttribute(NSLayoutAttributeHeight);
[superview addSubview:secondViewAttribute.view];
otherView = UIView.new;
[superview addSubview:otherView];
});
describe(@"equality chaining", ^{
it(@"should return same constraint when encountering equal for first time", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
MASViewConstraint *newConstraint = constraint.equalTo(secondViewAttribute);
[verify(constraint.delegate) addConstraint:(id)constraint];
... ... @@ -48,6 +56,7 @@ describe(@"equality chaining", ^{
});
it(@"should start new constraint when encountering equal subsequently", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
constraint.greaterThanOrEqualTo(secondViewAttribute);
MASViewConstraint *newConstraint = constraint.equalTo(secondViewAttribute);
... ... @@ -57,6 +66,7 @@ describe(@"equality chaining", ^{
});
it(@"should return same constraint when encountering greaterThanOrEqual for first time", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
MASViewConstraint *newConstraint = constraint.greaterThanOrEqualTo(secondViewAttribute);
[verify(constraint.delegate) addConstraint:(id)constraint];
... ... @@ -66,6 +76,7 @@ describe(@"equality chaining", ^{
});
it(@"should start new constraint when encountering greaterThanOrEqual subsequently", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
constraint.lessThanOrEqualTo(secondViewAttribute);
MASViewConstraint *newConstraint = constraint.greaterThanOrEqualTo(secondViewAttribute);
... ... @@ -75,6 +86,7 @@ describe(@"equality chaining", ^{
});
it(@"should return same constraint when encountering lessThanOrEqual for first time", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
MASViewConstraint *newConstraint = constraint.lessThanOrEqualTo(secondViewAttribute);
[verify(constraint.delegate) addConstraint:(id)constraint];
... ... @@ -84,6 +96,7 @@ describe(@"equality chaining", ^{
});
it(@"should start new constraint when encountering lessThanOrEqual subsequently", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
constraint.equalTo(secondViewAttribute);
MASViewConstraint *newConstraint = constraint.lessThanOrEqualTo(secondViewAttribute);
... ... @@ -93,6 +106,7 @@ describe(@"equality chaining", ^{
});
it(@"should not allow update of equal once layoutconstraint is created", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
[constraint commit];
expect(^{
... ... @@ -101,6 +115,7 @@ describe(@"equality chaining", ^{
});
it(@"should not allow update of lessThanOrEqual once layoutconstraint is created", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
[constraint commit];
expect(^{
... ... @@ -109,6 +124,7 @@ describe(@"equality chaining", ^{
});
it(@"should not allow update of greaterThanOrEqual once layoutconstraint is created", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_top;
[constraint commit];
expect(^{
... ... @@ -148,51 +164,51 @@ describe(@"multiplier & constant", ^{
});
it(@"should update sides offset only", ^{
MASViewConstraint *centerY = createConstraintWithLayoutAttribute(NSLayoutAttributeCenterY);
MASViewConstraint *centerY = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_centerY];
centerY.insets(UIEdgeInsetsMake(10, 10, 10, 10));
expect(centerY.layoutConstant).to.equal(0);
MASViewConstraint *top = createConstraintWithLayoutAttribute(NSLayoutAttributeTop);
MASViewConstraint *top = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_top];
top.insets(UIEdgeInsetsMake(15, 10, 10, 10));
expect(top.layoutConstant).to.equal(15);
MASViewConstraint *left = createConstraintWithLayoutAttribute(NSLayoutAttributeLeft);
MASViewConstraint *left = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_left];
left.insets(UIEdgeInsetsMake(10, 15, 10, 10));
expect(left.layoutConstant).to.equal(15);
MASViewConstraint *bottom = createConstraintWithLayoutAttribute(NSLayoutAttributeBottom);
MASViewConstraint *bottom = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_bottom];
bottom.insets(UIEdgeInsetsMake(10, 10, 15, 10));
expect(bottom.layoutConstant).to.equal(-15);
MASViewConstraint *right = createConstraintWithLayoutAttribute(NSLayoutAttributeRight);
MASViewConstraint *right = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_right];
right.insets(UIEdgeInsetsMake(10, 10, 10, 15));
expect(right.layoutConstant).to.equal(-15);
});
it(@"should update center offset only", ^{
MASViewConstraint *width = createConstraintWithLayoutAttribute(NSLayoutAttributeWidth);
MASViewConstraint *width = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_width];
width.centerOffset(CGPointMake(-20, -10));
expect(width.layoutConstant).to.equal(0);
MASViewConstraint *centerX = createConstraintWithLayoutAttribute(NSLayoutAttributeCenterX);
MASViewConstraint *centerX = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_centerX];
centerX.centerOffset(CGPointMake(-20, -10));
expect(centerX.layoutConstant).to.equal(-20);
MASViewConstraint *centerY = createConstraintWithLayoutAttribute(NSLayoutAttributeCenterY);
MASViewConstraint *centerY = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_centerY];
centerY.centerOffset(CGPointMake(-20, -10));
expect(centerY.layoutConstant).to.equal(-10);
});
it(@"should update size offset only", ^{
MASViewConstraint *bottom = createConstraintWithLayoutAttribute(NSLayoutAttributeBottom);
MASViewConstraint *bottom = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_bottom];
bottom.sizeOffset(CGSizeMake(-40, 55));
expect(bottom.layoutConstant).to.equal(0);
MASViewConstraint *width = createConstraintWithLayoutAttribute(NSLayoutAttributeWidth);
MASViewConstraint *width = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_width];
width.sizeOffset(CGSizeMake(-40, 55));
expect(width.layoutConstant).to.equal(-40);
MASViewConstraint *height = createConstraintWithLayoutAttribute(NSLayoutAttributeHeight);
MASViewConstraint *height = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_height];
height.sizeOffset(CGSizeMake(-40, 55));
expect(height.layoutConstant).to.equal(55);
});
... ... @@ -200,7 +216,8 @@ describe(@"multiplier & constant", ^{
describe(@"commit", ^{
it(@"should create layout constraint", ^{
it(@"should create layout constraint on commit", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_height;
constraint.equalTo(secondViewAttribute);
constraint.percent(0.5);
constraint.offset(10);
... ...
//
// SpecHelpers.h
// Masonry
//
// Created by Jonas Budelmann on 23/07/13.
// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
//
#import "MASCompositeConstraint.h"
#import "MASViewAttribute.h"
#import "MASViewConstraint.h"
static id (^createViewAttribute)(NSLayoutAttribute layoutAttribute) = ^id(NSLayoutAttribute layoutAttribute) {
UIView *view = UIView.new;
MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:view layoutAttribute:layoutAttribute];
return viewAttribute;
};
static id (^createConstraintWithLayoutAttribute)(NSLayoutAttribute layoutAttribute) = ^id(NSLayoutAttribute layoutAttribute) {
id delegate = mockProtocol(@protocol(MASConstraintDelegate));
MASViewConstraint *constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:createViewAttribute(layoutAttribute)];
constraint.delegate = delegate;
return constraint;
};
static id(^createCompositeWithType)(MASCompositeViewConstraintType type) = ^id(MASCompositeViewConstraintType type){
id delegate = mockProtocol(@protocol(MASConstraintDelegate));
UIView *view = UIView.new;
MASCompositeConstraint *composite = [[MASCompositeConstraint alloc] initWithView:view type:type];
composite.delegate = delegate;
return composite;
};
\ No newline at end of file