Authored by Jonas Budelmann

initial draft of debug helpers

@@ -28,6 +28,12 @@ @@ -28,6 +28,12 @@
28 DD52F268179CB346005CD195 /* MASViewAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = DD52F1E1179CAACA005CD195 /* MASViewAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; }; 28 DD52F268179CB346005CD195 /* MASViewAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = DD52F1E1179CAACA005CD195 /* MASViewAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; };
29 DD52F269179CB34A005CD195 /* MASViewConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = DD52F1E3179CAACA005CD195 /* MASViewConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; }; 29 DD52F269179CB34A005CD195 /* MASViewConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = DD52F1E3179CAACA005CD195 /* MASViewConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; };
30 DD52F26A179CB365005CD195 /* MASCompositeConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = DD52F1DC179CAACA005CD195 /* MASCompositeConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; }; 30 DD52F26A179CB365005CD195 /* MASCompositeConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = DD52F1DC179CAACA005CD195 /* MASCompositeConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; };
  31 + DD7CC16E17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD7CC16C17ACCF21007A469E /* NSLayoutConstraint+MASDebugAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
  32 + DD7CC16F17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7CC16D17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m */; };
  33 + DD7CC17217ACDC7A007A469E /* NSObject+MASDebugAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD7CC17017ACDC7A007A469E /* NSObject+MASDebugAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
  34 + DD7CC17317ACDC7A007A469E /* NSObject+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7CC17117ACDC7A007A469E /* NSObject+MASDebugAdditions.m */; };
  35 + DD93AAF317ACB647008F7D21 /* MASLayoutConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = DD93AAF117ACB647008F7D21 /* MASLayoutConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; };
  36 + DD93AAF417ACB647008F7D21 /* MASLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = DD93AAF217ACB647008F7D21 /* MASLayoutConstraint.m */; };
31 DDE2653F179D24E600D48565 /* UIView+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 37 DDE2653F179D24E600D48565 /* UIView+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
32 F0D61B353FCC42358F962A3C /* libPods-MasonryTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DE643A835A4447F4807FDBFA /* libPods-MasonryTests.a */; }; 38 F0D61B353FCC42358F962A3C /* libPods-MasonryTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DE643A835A4447F4807FDBFA /* libPods-MasonryTests.a */; };
33 /* End PBXBuildFile section */ 39 /* End PBXBuildFile section */
@@ -81,6 +87,12 @@ @@ -81,6 +87,12 @@
81 DD52F1E5179CAACA005CD195 /* UIView+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MASAdditions.h"; sourceTree = "<group>"; }; 87 DD52F1E5179CAACA005CD195 /* UIView+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MASAdditions.h"; sourceTree = "<group>"; };
82 DD52F1E6179CAACA005CD195 /* UIView+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+MASAdditions.m"; sourceTree = "<group>"; }; 88 DD52F1E6179CAACA005CD195 /* UIView+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+MASAdditions.m"; sourceTree = "<group>"; };
83 DD52F1ED179CAAEE005CD195 /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = "<group>"; }; 89 DD52F1ED179CAAEE005CD195 /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = "<group>"; };
  90 + DD7CC16C17ACCF21007A469E /* NSLayoutConstraint+MASDebugAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+MASDebugAdditions.h"; sourceTree = "<group>"; };
  91 + DD7CC16D17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+MASDebugAdditions.m"; sourceTree = "<group>"; };
  92 + DD7CC17017ACDC7A007A469E /* NSObject+MASDebugAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+MASDebugAdditions.h"; sourceTree = "<group>"; };
  93 + DD7CC17117ACDC7A007A469E /* NSObject+MASDebugAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+MASDebugAdditions.m"; sourceTree = "<group>"; };
  94 + DD93AAF117ACB647008F7D21 /* MASLayoutConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASLayoutConstraint.h; sourceTree = "<group>"; };
  95 + DD93AAF217ACB647008F7D21 /* MASLayoutConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASLayoutConstraint.m; sourceTree = "<group>"; };
84 DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MASShorthandAdditions.h"; sourceTree = "<group>"; }; 96 DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MASShorthandAdditions.h"; sourceTree = "<group>"; };
85 DE643A835A4447F4807FDBFA /* libPods-MasonryTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MasonryTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 97 DE643A835A4447F4807FDBFA /* libPods-MasonryTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MasonryTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
86 /* End PBXFileReference section */ 98 /* End PBXFileReference section */
@@ -195,6 +207,10 @@ @@ -195,6 +207,10 @@
195 DD52F1E5179CAACA005CD195 /* UIView+MASAdditions.h */, 207 DD52F1E5179CAACA005CD195 /* UIView+MASAdditions.h */,
196 DD52F1E6179CAACA005CD195 /* UIView+MASAdditions.m */, 208 DD52F1E6179CAACA005CD195 /* UIView+MASAdditions.m */,
197 DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */, 209 DDE2653D179D24E600D48565 /* UIView+MASShorthandAdditions.h */,
  210 + DD7CC17017ACDC7A007A469E /* NSObject+MASDebugAdditions.h */,
  211 + DD7CC17117ACDC7A007A469E /* NSObject+MASDebugAdditions.m */,
  212 + DD7CC16C17ACCF21007A469E /* NSLayoutConstraint+MASDebugAdditions.h */,
  213 + DD7CC16D17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m */,
198 ); 214 );
199 name = Additions; 215 name = Additions;
200 sourceTree = "<group>"; 216 sourceTree = "<group>";
@@ -211,6 +227,8 @@ @@ -211,6 +227,8 @@
211 DD52F1E2179CAACA005CD195 /* MASViewAttribute.m */, 227 DD52F1E2179CAACA005CD195 /* MASViewAttribute.m */,
212 DD52F1E3179CAACA005CD195 /* MASViewConstraint.h */, 228 DD52F1E3179CAACA005CD195 /* MASViewConstraint.h */,
213 DD52F1E4179CAACA005CD195 /* MASViewConstraint.m */, 229 DD52F1E4179CAACA005CD195 /* MASViewConstraint.m */,
  230 + DD93AAF117ACB647008F7D21 /* MASLayoutConstraint.h */,
  231 + DD93AAF217ACB647008F7D21 /* MASLayoutConstraint.m */,
214 ); 232 );
215 name = Modules; 233 name = Modules;
216 sourceTree = "<group>"; 234 sourceTree = "<group>";
@@ -229,7 +247,10 @@ @@ -229,7 +247,10 @@
229 DD52F267179CB342005CD195 /* MASConstraintMaker.h in Headers */, 247 DD52F267179CB342005CD195 /* MASConstraintMaker.h in Headers */,
230 DD52F268179CB346005CD195 /* MASViewAttribute.h in Headers */, 248 DD52F268179CB346005CD195 /* MASViewAttribute.h in Headers */,
231 DD52F269179CB34A005CD195 /* MASViewConstraint.h in Headers */, 249 DD52F269179CB34A005CD195 /* MASViewConstraint.h in Headers */,
  250 + DD93AAF317ACB647008F7D21 /* MASLayoutConstraint.h in Headers */,
232 DD52F26A179CB365005CD195 /* MASCompositeConstraint.h in Headers */, 251 DD52F26A179CB365005CD195 /* MASCompositeConstraint.h in Headers */,
  252 + DD7CC17217ACDC7A007A469E /* NSObject+MASDebugAdditions.h in Headers */,
  253 + DD7CC16E17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.h in Headers */,
233 ); 254 );
234 runOnlyForDeploymentPostprocessing = 0; 255 runOnlyForDeploymentPostprocessing = 0;
235 }; 256 };
@@ -367,6 +388,9 @@ @@ -367,6 +388,9 @@
367 DD52F1E9179CAACA005CD195 /* MASViewAttribute.m in Sources */, 388 DD52F1E9179CAACA005CD195 /* MASViewAttribute.m in Sources */,
368 DD52F1EA179CAACA005CD195 /* MASViewConstraint.m in Sources */, 389 DD52F1EA179CAACA005CD195 /* MASViewConstraint.m in Sources */,
369 DD52F1EB179CAACA005CD195 /* UIView+MASAdditions.m in Sources */, 390 DD52F1EB179CAACA005CD195 /* UIView+MASAdditions.m in Sources */,
  391 + DD93AAF417ACB647008F7D21 /* MASLayoutConstraint.m in Sources */,
  392 + DD7CC16F17ACCF22007A469E /* NSLayoutConstraint+MASDebugAdditions.m in Sources */,
  393 + DD7CC17317ACDC7A007A469E /* NSObject+MASDebugAdditions.m in Sources */,
370 ); 394 );
371 runOnlyForDeploymentPostprocessing = 0; 395 runOnlyForDeploymentPostprocessing = 0;
372 }; 396 };
@@ -13,15 +13,49 @@ typedef NS_ENUM(NSInteger, MASCompositeConstraintType) { @@ -13,15 +13,49 @@ typedef NS_ENUM(NSInteger, MASCompositeConstraintType) {
13 MASCompositeConstraintTypeEdges, //top, left, bottom, right 13 MASCompositeConstraintTypeEdges, //top, left, bottom, right
14 MASCompositeConstraintTypeSize, //width, height 14 MASCompositeConstraintTypeSize, //width, height
15 MASCompositeConstraintTypeCenter, //centerX, centerY 15 MASCompositeConstraintTypeCenter, //centerX, centerY
  16 + MASCompositeConstraintTypeUnknown, //could be mixture of any attributes
16 }; 17 };
17 18
  19 +/**
  20 + * A group of MASConstraint objects
  21 + * conforms to MASConstraint
  22 + */
18 @interface MASCompositeConstraint : NSObject <MASConstraint> 23 @interface MASCompositeConstraint : NSObject <MASConstraint>
19 24
  25 +/**
  26 + * Usually MASConstraintMaker but could be a parent MASConstraint
  27 + */
20 @property (nonatomic, weak) id<MASConstraintDelegate> delegate; 28 @property (nonatomic, weak) id<MASConstraintDelegate> delegate;
  29 +
  30 +/**
  31 + * default first item for any child MASConstraints
  32 + */
21 @property (nonatomic, weak, readonly) UIView *view; 33 @property (nonatomic, weak, readonly) UIView *view;
  34 +
  35 +/**
  36 + * type of Composite, used internally to generate child MASViewConstraits
  37 + */
22 @property (nonatomic, assign, readonly) MASCompositeConstraintType type; 38 @property (nonatomic, assign, readonly) MASCompositeConstraintType type;
23 39
  40 +/**
  41 + * Creates a composite and automatically generates child MASViewConstraints
  42 + * Appriopriate to the type
  43 + *
  44 + * @param view first item view
  45 + * @param type determines what kind of child constraints to generate
  46 + *
  47 + * @return a composite constraint
  48 + */
24 - (id)initWithView:(UIView *)view type:(MASCompositeConstraintType)type; 49 - (id)initWithView:(UIView *)view type:(MASCompositeConstraintType)type;
  50 +
  51 +/**
  52 + * Creates a composite with a predefined array of children
  53 + *
  54 + * @param view first item view
  55 + * @param children child MASConstraints
  56 + *
  57 + * @return a composite constraint
  58 + */
25 - (id)initWithView:(UIView *)view children:(NSArray *)children; 59 - (id)initWithView:(UIView *)view children:(NSArray *)children;
26 60
27 @end 61 @end
@@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
34 self = [super init]; 34 self = [super init];
35 if (!self) return nil; 35 if (!self) return nil;
36 36
  37 + _type = MASCompositeConstraintTypeUnknown;
37 _view = view; 38 _view = view;
38 _childConstraints = [children mutableCopy]; 39 _childConstraints = [children mutableCopy];
39 40
@@ -61,6 +62,8 @@ @@ -61,6 +62,8 @@
61 self.view.mas_centerX, self.view.mas_centerY 62 self.view.mas_centerX, self.view.mas_centerY
62 ]; 63 ];
63 break; 64 break;
  65 + default:
  66 + break;
64 } 67 }
65 68
66 for (MASViewAttribute *viewAttribute in viewAttributes) { 69 for (MASViewAttribute *viewAttribute in viewAttributes) {
@@ -192,6 +195,18 @@ @@ -192,6 +195,18 @@
192 return self; 195 return self;
193 } 196 }
194 197
  198 +#pragma mark - debug helpers
  199 +
  200 +- (id<MASConstraint> (^)(NSString *))debugName {
  201 + return ^id(NSString *debugName) {
  202 + int i = 0;
  203 + for (id<MASConstraint> constraint in self.childConstraints) {
  204 + constraint.debugName([NSString stringWithFormat:@"%@[%d]", debugName, i++]);
  205 + }
  206 + return self;
  207 + };
  208 +}
  209 +
195 #pragma mark - MASConstraint 210 #pragma mark - MASConstraint
196 211
197 - (void)commit { 212 - (void)commit {
@@ -17,33 +17,101 @@ enum { @@ -17,33 +17,101 @@ enum {
17 }; 17 };
18 typedef float MASLayoutPriority; 18 typedef float MASLayoutPriority;
19 19
  20 +/**
  21 + * Enables Constraints to be created with chainable syntax
  22 + * Constraint can represent single NSLayoutConstraint (MASViewConstraint)
  23 + * or a group of NSLayoutConstraints (MASComposisteConstraint)
  24 + */
20 @protocol MASConstraint <NSObject> 25 @protocol MASConstraint <NSObject>
21 26
22 -//NSLayoutConstraint constant proxies 27 +/**
  28 + * Modifies the NSLayoutConstraint constant,
  29 + * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
  30 + * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
  31 + */
23 @property (nonatomic, copy, readonly) id<MASConstraint> (^insets)(UIEdgeInsets insets); 32 @property (nonatomic, copy, readonly) id<MASConstraint> (^insets)(UIEdgeInsets insets);
  33 +
  34 +/**
  35 + * Modifies the NSLayoutConstraint constant,
  36 + * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
  37 + * NSLayoutAttributeWidth, NSLayoutAttributeHeight
  38 + */
24 @property (nonatomic, copy, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset); 39 @property (nonatomic, copy, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset);
  40 +
  41 +/**
  42 + * Modifies the NSLayoutConstraint constant,
  43 + * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
  44 + * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
  45 + */
25 @property (nonatomic, copy, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset); 46 @property (nonatomic, copy, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset);
  47 +
  48 +
  49 +/**
  50 + * Modifies the NSLayoutConstraint constant
  51 + */
26 @property (nonatomic, copy, readonly) id<MASConstraint> (^offset)(CGFloat offset); 52 @property (nonatomic, copy, readonly) id<MASConstraint> (^offset)(CGFloat offset);
27 53
28 -//NSLayoutConstraint multiplier proxies 54 +/**
  55 + * Sets the NSLayoutConstraint multiplier property
  56 + */
29 @property (nonatomic, copy, readonly) id<MASConstraint> (^percent)(CGFloat percent); 57 @property (nonatomic, copy, readonly) id<MASConstraint> (^percent)(CGFloat percent);
30 58
31 -//MASLayoutPriority proxies 59 +/**
  60 + * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
  61 + */
32 @property (nonatomic, copy, readonly) id<MASConstraint> (^priority)(MASLayoutPriority priority); 62 @property (nonatomic, copy, readonly) id<MASConstraint> (^priority)(MASLayoutPriority priority);
  63 +
  64 +/**
  65 + * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
  66 + */
33 @property (nonatomic, copy, readonly) id<MASConstraint> (^priorityLow)(); 67 @property (nonatomic, copy, readonly) id<MASConstraint> (^priorityLow)();
  68 +
  69 +/**
  70 + * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
  71 + */
34 @property (nonatomic, copy, readonly) id<MASConstraint> (^priorityMedium)(); 72 @property (nonatomic, copy, readonly) id<MASConstraint> (^priorityMedium)();
  73 +
  74 +/**
  75 + * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
  76 + */
35 @property (nonatomic, copy, readonly) id<MASConstraint> (^priorityHigh)(); 77 @property (nonatomic, copy, readonly) id<MASConstraint> (^priorityHigh)();
36 78
37 -//NSLayoutRelation proxies 79 +/**
  80 + * Sets the constraint relation to NSLayoutRelationEqual
  81 + * returns a block which accepts one of the following:
  82 + * MASViewAttribute, UIView, NSNumber, NSArray
  83 + * see readme for more details.
  84 + */
38 @property (nonatomic, copy, readonly) id<MASConstraint> (^equalTo)(id attr); 85 @property (nonatomic, copy, readonly) id<MASConstraint> (^equalTo)(id attr);
  86 +
  87 +/**
  88 + * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
  89 + * returns a block which accepts one of the following:
  90 + * MASViewAttribute, UIView, NSNumber, NSArray
  91 + * see readme for more details.
  92 + */
39 @property (nonatomic, copy, readonly) id<MASConstraint> (^greaterThanOrEqualTo)(id attr); 93 @property (nonatomic, copy, readonly) id<MASConstraint> (^greaterThanOrEqualTo)(id attr);
  94 +
  95 +/**
  96 + * Sets the constraint relation to NSLayoutRelationLessThanOrEqual
  97 + * returns a block which accepts one of the following:
  98 + * MASViewAttribute, UIView, NSNumber, NSArray
  99 + * see readme for more details.
  100 + */
40 @property (nonatomic, copy, readonly) id<MASConstraint> (^lessThanOrEqualTo)(id attr); 101 @property (nonatomic, copy, readonly) id<MASConstraint> (^lessThanOrEqualTo)(id attr);
41 102
42 -//semantic properties 103 +/**
  104 + * optional semantic property which has no effect but improves the readability of constraint
  105 + */
43 @property (nonatomic, copy, readonly) id<MASConstraint> with; 106 @property (nonatomic, copy, readonly) id<MASConstraint> with;
44 107
45 /** 108 /**
46 - Creates a NSLayoutConstraint. The constraint is added to the first view or the or the closest common superview of the first and second view. 109 + * Sets the constraint debug name
  110 + */
  111 +@property (nonatomic, copy, readonly) id<MASConstraint> (^debugName)(NSString* debugName);
  112 +
  113 +/**
  114 + * Creates a NSLayoutConstraint. The constraint is added to the first view or the or the closest common superview of the first and second view.
47 */ 115 */
48 - (void)commit; 116 - (void)commit;
49 117
@@ -52,7 +120,9 @@ typedef float MASLayoutPriority; @@ -52,7 +120,9 @@ typedef float MASLayoutPriority;
52 @protocol MASConstraintDelegate <NSObject> 120 @protocol MASConstraintDelegate <NSObject>
53 121
54 /** 122 /**
55 - Notifies the delegate when the constraint is has the minimum set of properties, has a NSLayoutRelation and view 123 + * Notifies the delegate when the constraint is has the minimum set of properties.
  124 + *
  125 + * @param constraint a constraint that has at least a NSLayoutRelation and view
56 */ 126 */
57 - (void)addConstraint:(id<MASConstraint>)constraint; 127 - (void)addConstraint:(id<MASConstraint>)constraint;
58 128
@@ -11,6 +11,10 @@ @@ -11,6 +11,10 @@
11 11
12 @interface MASConstraintMaker : NSObject 12 @interface MASConstraintMaker : NSObject
13 13
  14 +/**
  15 + * The following properties return a new MASViewConstraint
  16 + * with the first item set to the makers associated view and the appropriate MASViewAttribute
  17 + */
14 @property (nonatomic, strong, readonly) id<MASConstraint> left; 18 @property (nonatomic, strong, readonly) id<MASConstraint> left;
15 @property (nonatomic, strong, readonly) id<MASConstraint> top; 19 @property (nonatomic, strong, readonly) id<MASConstraint> top;
16 @property (nonatomic, strong, readonly) id<MASConstraint> right; 20 @property (nonatomic, strong, readonly) id<MASConstraint> right;
@@ -23,11 +27,39 @@ @@ -23,11 +27,39 @@
23 @property (nonatomic, strong, readonly) id<MASConstraint> centerY; 27 @property (nonatomic, strong, readonly) id<MASConstraint> centerY;
24 @property (nonatomic, strong, readonly) id<MASConstraint> baseline; 28 @property (nonatomic, strong, readonly) id<MASConstraint> baseline;
25 29
  30 +/**
  31 + * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
  32 + * which generates the appropriate MASViewConstraint children (top, left, bottom, right)
  33 + * with the first item set to the makers associated view
  34 + */
26 @property (nonatomic, strong, readonly) id<MASConstraint> edges; 35 @property (nonatomic, strong, readonly) id<MASConstraint> edges;
  36 +
  37 +/**
  38 + * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
  39 + * which generates the appropriate MASViewConstraint children (width, height)
  40 + * with the first item set to the makers associated view
  41 + */
27 @property (nonatomic, strong, readonly) id<MASConstraint> size; 42 @property (nonatomic, strong, readonly) id<MASConstraint> size;
  43 +
  44 +/**
  45 + * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
  46 + * which generates the appropriate MASViewConstraint children (centerX, centerY)
  47 + * with the first item set to the makers associated view
  48 + */
28 @property (nonatomic, strong, readonly) id<MASConstraint> center; 49 @property (nonatomic, strong, readonly) id<MASConstraint> center;
29 50
  51 +/**
  52 + * initialises the maker with a default view
  53 + *
  54 + * @param view any MASConstrait are created with this view as the first item
  55 + *
  56 + * @return a new MASConstraintMaker
  57 + */
30 - (id)initWithView:(UIView *)view; 58 - (id)initWithView:(UIView *)view;
  59 +
  60 +/**
  61 + * Calls commit method on any MASConstraints which requested to be added view MASConstraintDelegate
  62 + */
31 - (void)commit; 63 - (void)commit;
32 64
33 @end 65 @end
  1 +//
  2 +// MASLayoutConstraint.h
  3 +// Masonry
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +/**
  12 + * When you are debugging or printing the constraints attached to a view this subclass
  13 + * makes it easier to identify which constraints have been created via Masonry
  14 + */
  15 +@interface MASLayoutConstraint : NSLayoutConstraint
  16 +
  17 +@end
  1 +//
  2 +// MASLayoutConstraint.m
  3 +// Masonry
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import "MASLayoutConstraint.h"
  10 +
  11 +@implementation MASLayoutConstraint
  12 +
  13 +@end
@@ -16,9 +16,9 @@ @@ -16,9 +16,9 @@
16 - (id)initWithView:(UIView *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute; 16 - (id)initWithView:(UIView *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute;
17 17
18 /** 18 /**
19 - 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  
20 -  
21 - @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight 19 + * Determine whether the layoutAttribute is a size attribute
  20 + *
  21 + * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight
22 */ 22 */
23 - (BOOL)isSizeAttribute; 23 - (BOOL)isSizeAttribute;
24 24
@@ -8,13 +8,37 @@ @@ -8,13 +8,37 @@
8 8
9 #import "MASViewAttribute.h" 9 #import "MASViewAttribute.h"
10 #import "MASConstraint.h" 10 #import "MASConstraint.h"
  11 +#import "MASLayoutConstraint.h"
11 12
12 @interface MASViewConstraint : NSObject <MASConstraint, NSCopying> 13 @interface MASViewConstraint : NSObject <MASConstraint, NSCopying>
13 14
  15 +/**
  16 + * Usually MASConstraintMaker but could be a parent MASConstraint
  17 + */
14 @property (nonatomic, weak) id<MASConstraintDelegate> delegate; 18 @property (nonatomic, weak) id<MASConstraintDelegate> delegate;
  19 +
  20 +/**
  21 + * First item/view and first attribute of the NSLayoutConstraint
  22 + */
15 @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute; 23 @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute;
  24 +
  25 +/**
  26 + * Second item/view and second attribute of the NSLayoutConstraint
  27 + */
16 @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute; 28 @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute;
17 29
  30 +/**
  31 + * The generate MASLayoutConstraint could be nil if -commit has not been called
  32 + */
  33 +@property (nonatomic, strong, readonly) MASLayoutConstraint *layoutConstraint;
  34 +
  35 +/**
  36 + * initialises the MASViewConstraint with the first part of the equation
  37 + *
  38 + * @param firstViewAttribute view.mas_left, view.mas_width etc.
  39 + *
  40 + * @return a new view constraint
  41 + */
18 - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute; 42 - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute;
19 43
20 @end 44 @end
@@ -8,11 +8,13 @@ @@ -8,11 +8,13 @@
8 8
9 #import "MASViewConstraint.h" 9 #import "MASViewConstraint.h"
10 #import "MASCompositeConstraint.h" 10 #import "MASCompositeConstraint.h"
  11 +#import "MASLayoutConstraint.h"
  12 +#import "NSObject+MASDebugAdditions.h"
11 13
12 @interface MASViewConstraint () 14 @interface MASViewConstraint ()
13 15
14 @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute; 16 @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute;
15 -@property (nonatomic, strong) NSLayoutConstraint *layoutConstraint; 17 +@property (nonatomic, strong, readwrite) MASLayoutConstraint *layoutConstraint;
16 @property (nonatomic, assign) NSLayoutRelation layoutRelation; 18 @property (nonatomic, assign) NSLayoutRelation layoutRelation;
17 @property (nonatomic, assign) MASLayoutPriority layoutPriority; 19 @property (nonatomic, assign) MASLayoutPriority layoutPriority;
18 @property (nonatomic, assign) CGFloat layoutMultiplier; 20 @property (nonatomic, assign) CGFloat layoutMultiplier;
@@ -228,6 +230,15 @@ @@ -228,6 +230,15 @@
228 return self; 230 return self;
229 } 231 }
230 232
  233 +#pragma mark - debug helpers
  234 +
  235 +- (id<MASConstraint> (^)(NSString *))debugName {
  236 + return ^id(NSString *debugName) {
  237 + self.mas_debugName = debugName;
  238 + return self;
  239 + };
  240 +}
  241 +
231 #pragma mark - MASConstraint 242 #pragma mark - MASConstraint
232 243
233 - (void)commit { 244 - (void)commit {
@@ -243,15 +254,16 @@ @@ -243,15 +254,16 @@
243 } 254 }
244 255
245 256
246 - self.layoutConstraint = [NSLayoutConstraint constraintWithItem:firstLayoutItem  
247 - attribute:firstLayoutAttribute  
248 - relatedBy:self.layoutRelation  
249 - toItem:secondLayoutItem  
250 - attribute:secondLayoutAttribute  
251 - multiplier:self.layoutMultiplier  
252 - constant:self.layoutConstant]; 257 + self.layoutConstraint = [MASLayoutConstraint constraintWithItem:firstLayoutItem
  258 + attribute:firstLayoutAttribute
  259 + relatedBy:self.layoutRelation
  260 + toItem:secondLayoutItem
  261 + attribute:secondLayoutAttribute
  262 + multiplier:self.layoutMultiplier
  263 + constant:self.layoutConstant];
253 264
254 self.layoutConstraint.priority = self.layoutPriority; 265 self.layoutConstraint.priority = self.layoutPriority;
  266 + self.layoutConstraint.mas_debugName = self.mas_debugName;
255 267
256 if (secondLayoutItem) { 268 if (secondLayoutItem) {
257 UIView *closestCommonSuperview = nil; 269 UIView *closestCommonSuperview = nil;
@@ -276,8 +288,6 @@ @@ -276,8 +288,6 @@
276 288
277 [firstLayoutItem addConstraint:self.layoutConstraint]; 289 [firstLayoutItem addConstraint:self.layoutConstraint];
278 } 290 }
279 -  
280 -  
281 } 291 }
282 292
283 @end 293 @end
@@ -12,4 +12,6 @@ @@ -12,4 +12,6 @@
12 #import "MASCompositeConstraint.h" 12 #import "MASCompositeConstraint.h"
13 #import "MASViewAttribute.h" 13 #import "MASViewAttribute.h"
14 #import "MASViewConstraint.h" 14 #import "MASViewConstraint.h"
15 -#import "MASConstraintMaker.h"  
  15 +#import "MASConstraintMaker.h"
  16 +#import "MASLayoutConstraint.h"
  17 +#import "NSLayoutConstraint+MASDebugAdditions.h"
  1 +//
  2 +// NSLayoutConstraint+MASDebugAdditions.h
  3 +// Masonry
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +#import "NSObject+MASDebugAdditions.h"
  11 +
  12 +/**
  13 + * makes debug and log output of NSLayoutConstraints more readable
  14 + */
  15 +@interface NSLayoutConstraint (MASDebugAdditions)
  16 +
  17 +@end
  18 +
  1 +//
  2 +// NSLayoutConstraint+MASDebugAdditions.m
  3 +// Masonry
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import "NSLayoutConstraint+MASDebugAdditions.h"
  10 +#import "MASConstraint.h"
  11 +
  12 +@implementation NSLayoutConstraint (MASDebugAdditions)
  13 +
  14 +#pragma mark - description maps
  15 +
  16 ++ (NSDictionary *)layoutRelationDescriptionsByValue {
  17 + static dispatch_once_t once;
  18 + static NSDictionary *descriptionMap;
  19 + dispatch_once(&once, ^{
  20 + descriptionMap = @{
  21 + @(NSLayoutRelationEqual) : @"==",
  22 + @(NSLayoutRelationGreaterThanOrEqual) : @">=",
  23 + @(NSLayoutRelationLessThanOrEqual) : @"<=",
  24 + };
  25 + });
  26 + return descriptionMap;
  27 +}
  28 +
  29 ++ (NSDictionary *)layoutAttributeDescriptionsByValue {
  30 + static dispatch_once_t once;
  31 + static NSDictionary *descriptionMap;
  32 + dispatch_once(&once, ^{
  33 + descriptionMap = @{
  34 + @(NSLayoutAttributeTop) : @"top",
  35 + @(NSLayoutAttributeLeft) : @"left",
  36 + @(NSLayoutAttributeBottom) : @"bottom",
  37 + @(NSLayoutAttributeRight) : @"right",
  38 + @(NSLayoutAttributeLeading) : @"leading",
  39 + @(NSLayoutAttributeTrailing) : @"trailing",
  40 + @(NSLayoutAttributeWidth) : @"width",
  41 + @(NSLayoutAttributeHeight) : @"height",
  42 + @(NSLayoutAttributeCenterX) : @"centerX",
  43 + @(NSLayoutAttributeCenterY) : @"centerY",
  44 + @(NSLayoutAttributeBaseline) : @"baseline",
  45 + };
  46 + });
  47 + return descriptionMap;
  48 +}
  49 +
  50 +
  51 ++ (NSDictionary *)layoutPriorityDescriptionsByValue {
  52 + static dispatch_once_t once;
  53 + static NSDictionary *descriptionMap;
  54 + dispatch_once(&once, ^{
  55 + descriptionMap = @{
  56 + @(MASLayoutPriorityDefaultHigh) : @"high",
  57 + @(MASLayoutPriorityDefaultLow) : @"low",
  58 + @(MASLayoutPriorityDefaultMedium) : @"medium",
  59 + @(MASLayoutPriorityRequired) : @"required",
  60 + @(MASLayoutPriorityFittingSizeLevel) : @"fitting size",
  61 + };
  62 + });
  63 + return descriptionMap;
  64 +}
  65 +
  66 +#pragma mark - description override
  67 +
  68 ++ (NSString *)descriptionForObject:(id)obj {
  69 + if ([obj mas_debugName]) {
  70 + return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_debugName]];
  71 + }
  72 + return [NSString stringWithFormat:@"%@:%p", [obj class], obj];
  73 +}
  74 +
  75 +- (NSString *)description {
  76 + NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"];
  77 +
  78 + [description appendString:[self.class descriptionForObject:self]];
  79 +
  80 + [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]];
  81 + if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) {
  82 + [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.firstAttribute)]];
  83 + }
  84 +
  85 + [description appendFormat:@" %@", self.class.layoutRelationDescriptionsByValue[@(self.relation)]];
  86 +
  87 + if (self.secondItem) {
  88 + [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]];
  89 + }
  90 + if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) {
  91 + [description appendFormat:@".%@ ", self.class.layoutAttributeDescriptionsByValue[@(self.secondAttribute)]];
  92 + }
  93 +
  94 + if (self.multiplier != 1) {
  95 + [description appendFormat:@" * %f", self.multiplier];
  96 + }
  97 +
  98 + if (self.constant) {
  99 + [description appendFormat:@" %f", self.constant];
  100 + }
  101 +
  102 + if (self.priority != UILayoutPriorityRequired) {
  103 + [description appendFormat:@" ^%@", self.class.layoutPriorityDescriptionsByValue[@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]];
  104 + }
  105 +
  106 + [description appendString:@">"];
  107 + return description;
  108 +}
  109 +
  110 +@end
  1 +//
  2 +// NSObject+MASDebugAdditions.h
  3 +// Masonry
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@interface NSObject (MASDebugAdditions)
  12 +
  13 +@property (nonatomic, strong) NSString *mas_debugName;
  14 +
  15 +@end
  16 +
  17 +#define MASAttachDebugNames(...) \
  18 + NSDictionary *debugPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
  19 + for (id key in debugPairs.allKeys) { \
  20 + [debugPairs[key] setMas_debugName:key]; \
  21 + }
  22 +
  1 +//
  2 +// NSObject+MASDebugAdditions.m
  3 +// Masonry
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import "NSObject+MASDebugAdditions.h"
  10 +#import <objc/runtime.h>
  11 +
  12 +@implementation NSObject (MASDebugAdditions)
  13 +
  14 +- (NSString *)mas_debugName {
  15 + return objc_getAssociatedObject(self, @selector(mas_debugName));
  16 +}
  17 +
  18 +- (void)setMas_debugName:(NSString *)debugName {
  19 + objc_setAssociatedObject(self, @selector(mas_debugName), debugName, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  20 +}
  21 +
  22 +@end
@@ -10,9 +10,15 @@ @@ -10,9 +10,15 @@
10 #import "MASConstraintMaker.h" 10 #import "MASConstraintMaker.h"
11 #import "MASViewAttribute.h" 11 #import "MASViewAttribute.h"
12 12
  13 +/**
  14 + * Provides constraint maker block
  15 + * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs
  16 + */
13 @interface UIView (MASAdditions) 17 @interface UIView (MASAdditions)
14 18
15 -// following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute 19 +/**
  20 + * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute
  21 + */
16 @property (nonatomic, strong, readonly) MASViewAttribute *mas_left; 22 @property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
17 @property (nonatomic, strong, readonly) MASViewAttribute *mas_top; 23 @property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
18 @property (nonatomic, strong, readonly) MASViewAttribute *mas_right; 24 @property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
@@ -11,6 +11,10 @@ @@ -11,6 +11,10 @@
11 11
12 #ifdef MAS_SHORTHAND 12 #ifdef MAS_SHORTHAND
13 13
  14 +/**
  15 + * Shorthand view additions without the 'mas_' prefixes,
  16 + * only enabled if MAS_SHORTHAND is defined
  17 + */
14 @interface UIView (MASShorthandAdditions) 18 @interface UIView (MASShorthandAdditions)
15 19
16 @property (nonatomic, strong, readonly) MASViewAttribute *left; 20 @property (nonatomic, strong, readonly) MASViewAttribute *left;
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 DD52F254179CADC0005CD195 /* MASExampleSidesView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD52F24E179CADC0005CD195 /* MASExampleSidesView.m */; }; 19 DD52F254179CADC0005CD195 /* MASExampleSidesView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD52F24E179CADC0005CD195 /* MASExampleSidesView.m */; };
20 DD52F255179CADC0005CD195 /* MASExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD52F250179CADC0005CD195 /* MASExampleViewController.m */; }; 20 DD52F255179CADC0005CD195 /* MASExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD52F250179CADC0005CD195 /* MASExampleViewController.m */; };
21 DD52F26E179CBA05005CD195 /* libMasonry.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DD52F26D179CBA05005CD195 /* libMasonry.a */; }; 21 DD52F26E179CBA05005CD195 /* libMasonry.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DD52F26D179CBA05005CD195 /* libMasonry.a */; };
  22 + DD7CC17617ACE990007A469E /* MASExampleDebuggingView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7CC17517ACE990007A469E /* MASExampleDebuggingView.m */; };
22 DDF3875C179D648D00178773 /* MASExampleAnimatedView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */; }; 23 DDF3875C179D648D00178773 /* MASExampleAnimatedView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */; };
23 /* End PBXBuildFile section */ 24 /* End PBXBuildFile section */
24 25
@@ -44,6 +45,8 @@ @@ -44,6 +45,8 @@
44 DD52F24F179CADC0005CD195 /* MASExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleViewController.h; sourceTree = "<group>"; }; 45 DD52F24F179CADC0005CD195 /* MASExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleViewController.h; sourceTree = "<group>"; };
45 DD52F250179CADC0005CD195 /* MASExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleViewController.m; sourceTree = "<group>"; }; 46 DD52F250179CADC0005CD195 /* MASExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleViewController.m; sourceTree = "<group>"; };
46 DD52F26D179CBA05005CD195 /* libMasonry.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libMasonry.a; sourceTree = BUILT_PRODUCTS_DIR; }; 47 DD52F26D179CBA05005CD195 /* libMasonry.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libMasonry.a; sourceTree = BUILT_PRODUCTS_DIR; };
  48 + DD7CC17417ACE990007A469E /* MASExampleDebuggingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleDebuggingView.h; sourceTree = "<group>"; };
  49 + DD7CC17517ACE990007A469E /* MASExampleDebuggingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleDebuggingView.m; sourceTree = "<group>"; };
47 DDF3875A179D648D00178773 /* MASExampleAnimatedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleAnimatedView.h; sourceTree = "<group>"; }; 50 DDF3875A179D648D00178773 /* MASExampleAnimatedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleAnimatedView.h; sourceTree = "<group>"; };
48 DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleAnimatedView.m; sourceTree = "<group>"; }; 51 DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleAnimatedView.m; sourceTree = "<group>"; };
49 /* End PBXFileReference section */ 52 /* End PBXFileReference section */
@@ -125,6 +128,8 @@ @@ -125,6 +128,8 @@
125 DD52F24E179CADC0005CD195 /* MASExampleSidesView.m */, 128 DD52F24E179CADC0005CD195 /* MASExampleSidesView.m */,
126 DDF3875A179D648D00178773 /* MASExampleAnimatedView.h */, 129 DDF3875A179D648D00178773 /* MASExampleAnimatedView.h */,
127 DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */, 130 DDF3875B179D648D00178773 /* MASExampleAnimatedView.m */,
  131 + DD7CC17417ACE990007A469E /* MASExampleDebuggingView.h */,
  132 + DD7CC17517ACE990007A469E /* MASExampleDebuggingView.m */,
128 ); 133 );
129 name = Views; 134 name = Views;
130 sourceTree = "<group>"; 135 sourceTree = "<group>";
@@ -211,6 +216,7 @@ @@ -211,6 +216,7 @@
211 DD52F254179CADC0005CD195 /* MASExampleSidesView.m in Sources */, 216 DD52F254179CADC0005CD195 /* MASExampleSidesView.m in Sources */,
212 DD52F255179CADC0005CD195 /* MASExampleViewController.m in Sources */, 217 DD52F255179CADC0005CD195 /* MASExampleViewController.m in Sources */,
213 DDF3875C179D648D00178773 /* MASExampleAnimatedView.m in Sources */, 218 DDF3875C179D648D00178773 /* MASExampleAnimatedView.m in Sources */,
  219 + DD7CC17617ACE990007A469E /* MASExampleDebuggingView.m in Sources */,
214 ); 220 );
215 runOnlyForDeploymentPostprocessing = 0; 221 runOnlyForDeploymentPostprocessing = 0;
216 }; 222 };
@@ -8,13 +8,19 @@ @@ -8,13 +8,19 @@
8 8
9 #import "MASExampleBasicView.h" 9 #import "MASExampleBasicView.h"
10 10
  11 +@interface MASExampleBasicView ()
  12 +
  13 +@property (nonatomic, strong) UIView *view1;
  14 +
  15 +@end
  16 +
11 @implementation MASExampleBasicView 17 @implementation MASExampleBasicView
12 18
13 - (id)init { 19 - (id)init {
14 self = [super init]; 20 self = [super init];
15 if (!self) return nil; 21 if (!self) return nil;
16 22
17 - UIView *view1 = UIView.new; 23 + UIView *view1 = self.view1 = UIView.new;
18 view1.backgroundColor = UIColor.greenColor; 24 view1.backgroundColor = UIColor.greenColor;
19 view1.layer.borderColor = UIColor.blackColor.CGColor; 25 view1.layer.borderColor = UIColor.blackColor.CGColor;
20 view1.layer.borderWidth = 2; 26 view1.layer.borderWidth = 2;
@@ -35,6 +41,14 @@ @@ -35,6 +41,14 @@
35 UIView *superview = self; 41 UIView *superview = self;
36 int padding = 10; 42 int padding = 10;
37 43
  44 + //debug names
  45 +// view1.mas_debugName = @"view1";
  46 +// view2.mas_debugName = @"view2";
  47 +// view3.mas_debugName = @"view3";
  48 +// superview.mas_debugName = @"superview";
  49 + //or
  50 + MASAttachDebugNames(self.view1, view2, view3, superview);
  51 +
38 //if you want to use Masonry without the mas_ prefix 52 //if you want to use Masonry without the mas_ prefix
39 //define MAS_SHORTHAND before importing Masonry.h see MasonryExamples-Prefix.pch 53 //define MAS_SHORTHAND before importing Masonry.h see MasonryExamples-Prefix.pch
40 [view1 makeConstraints:^(MASConstraintMaker *make) { 54 [view1 makeConstraints:^(MASConstraintMaker *make) {
@@ -64,7 +78,7 @@ @@ -64,7 +78,7 @@
64 make.left.equalTo(superview.mas_left).offset(padding); 78 make.left.equalTo(superview.mas_left).offset(padding);
65 make.bottom.equalTo(superview.mas_bottom).offset(-padding); 79 make.bottom.equalTo(superview.mas_bottom).offset(-padding);
66 make.right.equalTo(superview.mas_right).offset(-padding); 80 make.right.equalTo(superview.mas_right).offset(-padding);
67 - 81 + make.edges.equalTo(@1).debugName(@"DumbConstraint");
68 make.height.equalTo(@[view1.mas_height, view2.mas_height]); //can pass array of attributes 82 make.height.equalTo(@[view1.mas_height, view2.mas_height]); //can pass array of attributes
69 }]; 83 }];
70 84
  1 +//
  2 +// MASExampleDebuggingView.h
  3 +// MasonryExamples
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface MASExampleDebuggingView : UIView
  12 +
  13 +@end
  1 +//
  2 +// MASExampleDebuggingView.m
  3 +// MasonryExamples
  4 +//
  5 +// Created by Jonas Budelmann on 3/08/13.
  6 +// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7 +//
  8 +
  9 +#import "MASExampleDebuggingView.h"
  10 +
  11 +@implementation MASExampleDebuggingView
  12 +
  13 +
  14 +
  15 +@end
@@ -13,7 +13,6 @@ @@ -13,7 +13,6 @@
13 13
14 @interface MASViewConstraint () 14 @interface MASViewConstraint ()
15 15
16 -@property (nonatomic, strong) NSLayoutConstraint *layoutConstraint;  
17 @property (nonatomic, assign) NSLayoutRelation layoutRelation; 16 @property (nonatomic, assign) NSLayoutRelation layoutRelation;
18 @property (nonatomic, assign) MASLayoutPriority layoutPriority; 17 @property (nonatomic, assign) MASLayoutPriority layoutPriority;
19 @property (nonatomic, assign) CGFloat layoutMultiplier; 18 @property (nonatomic, assign) CGFloat layoutMultiplier;