Authored by Jonas Budelmann

Merge pull request #191 from xserver/master

example variable rename.
... ... @@ -22,23 +22,23 @@
self = [super init];
if (!self) return nil;
UIView *view1 = UIView.new;
view1.backgroundColor = UIColor.greenColor;
view1.layer.borderColor = UIColor.blackColor.CGColor;
view1.layer.borderWidth = 2;
[self addSubview:view1];
UIView *view2 = UIView.new;
view2.backgroundColor = UIColor.redColor;
view2.layer.borderColor = UIColor.blackColor.CGColor;
view2.layer.borderWidth = 2;
[self addSubview:view2];
UIView *view3 = UIView.new;
view3.backgroundColor = UIColor.blueColor;
view3.layer.borderColor = UIColor.blackColor.CGColor;
view3.layer.borderWidth = 2;
[self addSubview:view3];
UIView *greenView = UIView.new;
greenView.backgroundColor = UIColor.greenColor;
greenView.layer.borderColor = UIColor.blackColor.CGColor;
greenView.layer.borderWidth = 2;
[self addSubview:greenView];
UIView *redView = UIView.new;
redView.backgroundColor = UIColor.redColor;
redView.layer.borderColor = UIColor.blackColor.CGColor;
redView.layer.borderWidth = 2;
[self addSubview:redView];
UIView *blueView = UIView.new;
blueView.backgroundColor = UIColor.blueColor;
blueView.layer.borderColor = UIColor.blackColor.CGColor;
blueView.layer.borderWidth = 2;
[self addSubview:blueView];
UIView *superview = self;
int padding = self.padding = 10;
... ... @@ -46,34 +46,34 @@
self.animatableConstraints = NSMutableArray.new;
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
[greenView mas_makeConstraints:^(MASConstraintMaker *make) {
[self.animatableConstraints addObjectsFromArray:@[
make.edges.equalTo(superview).insets(paddingInsets).priorityLow(),
make.bottom.equalTo(view3.mas_top).offset(-padding),
make.bottom.equalTo(blueView.mas_top).offset(-padding),
]];
make.size.equalTo(view2);
make.height.equalTo(view3.mas_height);
make.size.equalTo(redView);
make.height.equalTo(blueView.mas_height);
}];
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
[self.animatableConstraints addObjectsFromArray:@[
make.edges.equalTo(superview).insets(paddingInsets).priorityLow(),
make.left.equalTo(view1.mas_right).offset(padding),
make.bottom.equalTo(view3.mas_top).offset(-padding),
make.left.equalTo(greenView.mas_right).offset(padding),
make.bottom.equalTo(blueView.mas_top).offset(-padding),
]];
make.size.equalTo(view1);
make.height.equalTo(view3.mas_height);
make.size.equalTo(greenView);
make.height.equalTo(blueView.mas_height);
}];
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
[self.animatableConstraints addObjectsFromArray:@[
make.edges.equalTo(superview).insets(paddingInsets).priorityLow(),
]];
make.height.equalTo(view1.mas_height);
make.height.equalTo(view2.mas_height);
make.height.equalTo(greenView.mas_height);
make.height.equalTo(redView.mas_height);
}];
return self;
... ...
... ... @@ -14,29 +14,29 @@
self = [super init];
if (!self) return nil;
UIView *view1 = UIView.new;
view1.backgroundColor = UIColor.greenColor;
view1.layer.borderColor = UIColor.blackColor.CGColor;
view1.layer.borderWidth = 2;
[self addSubview:view1];
UIView *view2 = UIView.new;
view2.backgroundColor = UIColor.redColor;
view2.layer.borderColor = UIColor.blackColor.CGColor;
view2.layer.borderWidth = 2;
[self addSubview:view2];
UIView *view3 = UIView.new;
view3.backgroundColor = UIColor.blueColor;
view3.layer.borderColor = UIColor.blackColor.CGColor;
view3.layer.borderWidth = 2;
[self addSubview:view3];
UIView *greenView = UIView.new;
greenView.backgroundColor = UIColor.greenColor;
greenView.layer.borderColor = UIColor.blackColor.CGColor;
greenView.layer.borderWidth = 2;
[self addSubview:greenView];
UIView *redView = UIView.new;
redView.backgroundColor = UIColor.redColor;
redView.layer.borderColor = UIColor.blackColor.CGColor;
redView.layer.borderWidth = 2;
[self addSubview:redView];
UIView *blueView = UIView.new;
blueView.backgroundColor = UIColor.blueColor;
blueView.layer.borderColor = UIColor.blackColor.CGColor;
blueView.layer.borderWidth = 2;
[self addSubview:blueView];
UIView *superview = self;
UIEdgeInsets padding = UIEdgeInsetsMake(15, 10, 15, 10);
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
[greenView mas_makeConstraints:^(MASConstraintMaker *make) {
// chain attributes
make.top.and.left.equalTo(superview).insets(padding);
... ... @@ -44,31 +44,31 @@
// make.top.greaterThanOrEqualTo(superview).insets(padding);
// make.left.greaterThanOrEqualTo(superview).insets(padding);
make.bottom.equalTo(view3.mas_top).insets(padding);
make.right.equalTo(view2.mas_left).insets(padding);
make.width.equalTo(view2.mas_width);
make.bottom.equalTo(blueView.mas_top).insets(padding);
make.right.equalTo(redView.mas_left).insets(padding);
make.width.equalTo(redView.mas_width);
make.height.equalTo(@[view2, view3]);
make.height.equalTo(@[redView, blueView]);
}];
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
// chain attributes
make.top.and.right.equalTo(superview).insets(padding);
make.left.equalTo(view1.mas_right).insets(padding);
make.bottom.equalTo(view3.mas_top).insets(padding);
make.width.equalTo(view1.mas_width);
make.left.equalTo(greenView.mas_right).insets(padding);
make.bottom.equalTo(blueView.mas_top).insets(padding);
make.width.equalTo(greenView.mas_width);
make.height.equalTo(@[view1, view3]);
make.height.equalTo(@[greenView, blueView]);
}];
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(view1.mas_bottom).insets(padding);
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(greenView.mas_bottom).insets(padding);
// chain attributes
make.left.right.and.bottom.equalTo(superview).insets(padding);
make.height.equalTo(@[view1, view2]);
make.height.equalTo(@[greenView, redView]);
}];
return self;
... ...
... ... @@ -14,57 +14,57 @@
self = [super init];
if (!self) return nil;
UIView *view1 = UIView.new;
view1.backgroundColor = UIColor.greenColor;
view1.layer.borderColor = UIColor.blackColor.CGColor;
view1.layer.borderWidth = 2;
[self addSubview:view1];
UIView *greenView = UIView.new;
greenView.backgroundColor = UIColor.greenColor;
greenView.layer.borderColor = UIColor.blackColor.CGColor;
greenView.layer.borderWidth = 2;
[self addSubview:greenView];
UIView *view2 = UIView.new;
view2.backgroundColor = UIColor.redColor;
view2.layer.borderColor = UIColor.blackColor.CGColor;
view2.layer.borderWidth = 2;
[self addSubview:view2];
UIView *redView = UIView.new;
redView.backgroundColor = UIColor.redColor;
redView.layer.borderColor = UIColor.blackColor.CGColor;
redView.layer.borderWidth = 2;
[self addSubview:redView];
UIView *view3 = UIView.new;
view3.backgroundColor = UIColor.blueColor;
view3.layer.borderColor = UIColor.blackColor.CGColor;
view3.layer.borderWidth = 2;
[self addSubview:view3];
UIView *blueView = UIView.new;
blueView.backgroundColor = UIColor.blueColor;
blueView.layer.borderColor = UIColor.blackColor.CGColor;
blueView.layer.borderWidth = 2;
[self addSubview:blueView];
UIView *superview = self;
int padding = 10;
//if you want to use Masonry without the mas_ prefix
//define MAS_SHORTHAND before importing Masonry.h see Masonry iOS Examples-Prefix.pch
[view1 makeConstraints:^(MASConstraintMaker *make) {
[greenView makeConstraints:^(MASConstraintMaker *make) {
make.top.greaterThanOrEqualTo(superview.top).offset(padding);
make.left.equalTo(superview.left).offset(padding);
make.bottom.equalTo(view3.top).offset(-padding);
make.right.equalTo(view2.left).offset(-padding);
make.width.equalTo(view2.width);
make.bottom.equalTo(blueView.top).offset(-padding);
make.right.equalTo(redView.left).offset(-padding);
make.width.equalTo(redView.width);
make.height.equalTo(view2.height);
make.height.equalTo(view3.height);
make.height.equalTo(redView.height);
make.height.equalTo(blueView.height);
}];
//with is semantic and option
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(superview.mas_top).with.offset(padding); //with with
make.left.equalTo(view1.mas_right).offset(padding); //without with
make.bottom.equalTo(view3.mas_top).offset(-padding);
make.left.equalTo(greenView.mas_right).offset(padding); //without with
make.bottom.equalTo(blueView.mas_top).offset(-padding);
make.right.equalTo(superview.mas_right).offset(-padding);
make.width.equalTo(view1.mas_width);
make.width.equalTo(greenView.mas_width);
make.height.equalTo(@[view1, view3]); //can pass array of views
make.height.equalTo(@[greenView, blueView]); //can pass array of views
}];
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(view1.mas_bottom).offset(padding);
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(greenView.mas_bottom).offset(padding);
make.left.equalTo(superview.mas_left).offset(padding);
make.bottom.equalTo(superview.mas_bottom).offset(-padding);
make.right.equalTo(superview.mas_right).offset(-padding);
make.height.equalTo(@[view1.mas_height, view2.mas_height]); //can pass array of attributes
make.height.equalTo(@[greenView.mas_height, redView.mas_height]); //can pass array of attributes
}];
return self;
... ...
... ... @@ -14,21 +14,21 @@
self = [super init];
if (!self) return nil;
UIView *view1 = UIView.new;
view1.backgroundColor = UIColor.purpleColor;
view1.layer.borderColor = UIColor.blackColor.CGColor;
view1.layer.borderWidth = 2;
[self addSubview:view1];
UIView *purpleView = UIView.new;
purpleView.backgroundColor = UIColor.purpleColor;
purpleView.layer.borderColor = UIColor.blackColor.CGColor;
purpleView.layer.borderWidth = 2;
[self addSubview:purpleView];
UIView *view2 = UIView.new;
view2.backgroundColor = UIColor.orangeColor;
view2.layer.borderColor = UIColor.blackColor.CGColor;
view2.layer.borderWidth = 2;
[self addSubview:view2];
UIView *orangeView = UIView.new;
orangeView.backgroundColor = UIColor.orangeColor;
orangeView.layer.borderColor = UIColor.blackColor.CGColor;
orangeView.layer.borderWidth = 2;
[self addSubview:orangeView];
//example of using constants
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
[purpleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@20);
make.left.equalTo(@20);
make.bottom.equalTo(@-20);
... ... @@ -37,7 +37,7 @@
// auto-boxing macros allow you to simply use scalars and structs, they will be wrapped automatically
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
[orangeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(CGPointMake(0, 50));
make.size.equalTo(CGSizeMake(200, 100));
}];
... ...
... ... @@ -14,74 +14,74 @@
self = [super init];
if (!self) return nil;
UIView *view1 = UIView.new;
view1.backgroundColor = UIColor.greenColor;
view1.layer.borderColor = UIColor.blackColor.CGColor;
view1.layer.borderWidth = 2;
[self addSubview:view1];
UIView *greenView = UIView.new;
greenView.backgroundColor = UIColor.greenColor;
greenView.layer.borderColor = UIColor.blackColor.CGColor;
greenView.layer.borderWidth = 2;
[self addSubview:greenView];
UIView *view2 = UIView.new;
view2.backgroundColor = UIColor.redColor;
view2.layer.borderColor = UIColor.blackColor.CGColor;
view2.layer.borderWidth = 2;
[self addSubview:view2];
UIView *redView = UIView.new;
redView.backgroundColor = UIColor.redColor;
redView.layer.borderColor = UIColor.blackColor.CGColor;
redView.layer.borderWidth = 2;
[self addSubview:redView];
UILabel *view3 = UILabel.new;
view3.backgroundColor = UIColor.blueColor;
view3.numberOfLines = 3;
view3.textAlignment = NSTextAlignmentCenter;
view3.font = [UIFont systemFontOfSize:24];
view3.textColor = UIColor.whiteColor;
view3.text = @"this should look broken! check your console!";
view3.layer.borderColor = UIColor.blackColor.CGColor;
view3.layer.borderWidth = 2;
[self addSubview:view3];
UILabel *blueView = UILabel.new;
blueView.backgroundColor = UIColor.blueColor;
blueView.numberOfLines = 3;
blueView.textAlignment = NSTextAlignmentCenter;
blueView.font = [UIFont systemFontOfSize:24];
blueView.textColor = UIColor.whiteColor;
blueView.text = @"this should look broken! check your console!";
blueView.layer.borderColor = UIColor.blackColor.CGColor;
blueView.layer.borderWidth = 2;
[self addSubview:blueView];
UIView *superview = self;
int padding = 10;
//you can attach debug keys to views like so:
// view1.mas_key = @"view1";
// view2.mas_key = @"view2";
// view3.mas_key = @"view3";
// greenView.mas_key = @"greenView";
// redView.mas_key = @"redView";
// blueView.mas_key = @"blueView";
// superview.mas_key = @"superview";
//OR you can attach keys automagically like so:
MASAttachKeys(view1, view2, view3, superview);
MASAttachKeys(greenView, redView, blueView, superview);
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
//you can also attach debug keys to constaints
make.edges.equalTo(@1).key(@"ConflictingConstraint"); //composite constraint keys will be indexed
make.height.greaterThanOrEqualTo(@5000).key(@"ConstantConstraint");
make.top.equalTo(view1.mas_bottom).offset(padding);
make.top.equalTo(greenView.mas_bottom).offset(padding);
make.left.equalTo(superview.mas_left).offset(padding);
make.bottom.equalTo(superview.mas_bottom).offset(-padding).key(@"BottomConstraint");
make.right.equalTo(superview.mas_right).offset(-padding);
make.height.equalTo(view1.mas_height);
make.height.equalTo(view2.mas_height).key(@340954); //anything can be a key
make.height.equalTo(greenView.mas_height);
make.height.equalTo(redView.mas_height).key(@340954); //anything can be a key
}];
[view1 makeConstraints:^(MASConstraintMaker *make) {
[greenView makeConstraints:^(MASConstraintMaker *make) {
make.top.greaterThanOrEqualTo(superview.top).offset(padding);
make.left.equalTo(superview.left).offset(padding);
make.bottom.equalTo(view3.top).offset(-padding);
make.right.equalTo(view2.left).offset(-padding);
make.width.equalTo(view2.width);
make.bottom.equalTo(blueView.top).offset(-padding);
make.right.equalTo(redView.left).offset(-padding);
make.width.equalTo(redView.width);
make.height.equalTo(view2.height);
make.height.equalTo(view3.height);
make.height.equalTo(redView.height);
make.height.equalTo(blueView.height);
}];
//with is semantic and option
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(superview.mas_top).with.offset(padding);
make.left.equalTo(view1.mas_right).offset(padding);
make.bottom.equalTo(view3.mas_top).offset(-padding);
make.left.equalTo(greenView.mas_right).offset(padding);
make.bottom.equalTo(blueView.mas_top).offset(-padding);
make.right.equalTo(superview.mas_right).offset(-padding);
make.width.equalTo(view1.mas_width);
make.width.equalTo(greenView.mas_width);
make.height.equalTo(@[view1, view3]);
make.height.equalTo(@[greenView, blueView]);
}];
return self;
... ...