Authored by Jonas Budelmann

Update README.md

Showing 1 changed file with 13 additions and 12 deletions
@@ -14,7 +14,7 @@ view1.translatesAutoresizingMaskIntoConstraints = NO; @@ -14,7 +14,7 @@ view1.translatesAutoresizingMaskIntoConstraints = NO;
14 view1.backgroundColor = [UIColor greenColor]; 14 view1.backgroundColor = [UIColor greenColor];
15 [superview addSubview:view1]; 15 [superview addSubview:view1];
16 16
17 -int padding = 10; 17 +UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
18 18
19 [superview addConstraints:@[ 19 [superview addConstraints:@[
20 20
@@ -25,7 +25,7 @@ int padding = 10; @@ -25,7 +25,7 @@ int padding = 10;
25 toItem:superview 25 toItem:superview
26 attribute:NSLayoutAttributeTop 26 attribute:NSLayoutAttributeTop
27 multiplier:1.0 27 multiplier:1.0
28 - constant:padding], 28 + constant:padding.top],
29 29
30 [NSLayoutConstraint constraintWithItem:view1 30 [NSLayoutConstraint constraintWithItem:view1
31 attribute:NSLayoutAttributeLeft 31 attribute:NSLayoutAttributeLeft
@@ -33,7 +33,7 @@ int padding = 10; @@ -33,7 +33,7 @@ int padding = 10;
33 toItem:superview 33 toItem:superview
34 attribute:NSLayoutAttributeLeft 34 attribute:NSLayoutAttributeLeft
35 multiplier:1.0 35 multiplier:1.0
36 - constant:padding], 36 + constant:padding.left],
37 37
38 [NSLayoutConstraint constraintWithItem:view1 38 [NSLayoutConstraint constraintWithItem:view1
39 attribute:NSLayoutAttributeBottom 39 attribute:NSLayoutAttributeBottom
@@ -41,7 +41,7 @@ int padding = 10; @@ -41,7 +41,7 @@ int padding = 10;
41 toItem:superview 41 toItem:superview
42 attribute:NSLayoutAttributeBottom 42 attribute:NSLayoutAttributeBottom
43 multiplier:1.0 43 multiplier:1.0
44 - constant:-padding], 44 + constant:-padding.bottom],
45 45
46 [NSLayoutConstraint constraintWithItem:view1 46 [NSLayoutConstraint constraintWithItem:view1
47 attribute:NSLayoutAttributeRight 47 attribute:NSLayoutAttributeRight
@@ -49,29 +49,30 @@ int padding = 10; @@ -49,29 +49,30 @@ int padding = 10;
49 toItem:superview 49 toItem:superview
50 attribute:NSLayoutAttributeRight 50 attribute:NSLayoutAttributeRight
51 multiplier:1 51 multiplier:1
52 - constant:-padding], 52 + constant:-padding.right],
53 53
54 ]]; 54 ]];
55 ``` 55 ```
56 Even with such a simple example the code needed is quite verbose and quickly becomes unreadable when you have more than 2 or 3 views. 56 Even with such a simple example the code needed is quite verbose and quickly becomes unreadable when you have more than 2 or 3 views.
57 57
58 -### Meet your Maker! 58 +### Prepare to meet your Maker!
59 59
60 heres the same constraints created using MASConstraintMaker 60 heres the same constraints created using MASConstraintMaker
61 61
62 ```obj-c 62 ```obj-c
  63 +UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
  64 +
63 [view1 makeConstraints:^(MASConstraintMaker *make) { 65 [view1 makeConstraints:^(MASConstraintMaker *make) {
64 - make.top.equalTo(superview.top).with.offset(padding);  
65 - make.left.equalTo(superview.left).with.offset(padding);  
66 - make.bottom.equalTo(superview.bottom).with.offset(-padding);  
67 - make.right.equalTo(superview.right).with.offset(-padding); 66 + make.top.equalTo(superview.top).with.offset(padding.top); //with is an optional semantic filler
  67 + make.left.equalTo(superview.left).with.offset(padding.left);
  68 + make.bottom.equalTo(superview.bottom).with.offset(-padding.bottom);
  69 + make.right.equalTo(superview.right).with.offset(-padding.right);
68 }]; 70 }];
69 ``` 71 ```
70 or ever shorter 72 or ever shorter
71 ```obj-c 73 ```obj-c
72 [view1 makeConstraints:^(MASConstraintMaker *make) { 74 [view1 makeConstraints:^(MASConstraintMaker *make) {
73 - UIEdgeInsets paddingInsets = UIEdgeInsetsMake(padding, padding, padding, padding);  
74 - make.edges.equalTo(superview).insets(paddingInsets); 75 + make.edges.equalTo(superview).insets(padding);
75 }]; 76 }];
76 ``` 77 ```
77 78