First, we're going to introduce a header file
#import "Masonry.h"
Then we can initialize a control object such as a Label object
New ]; = [Uicolor redcolor]; [Self.view Addsubview:label1]; // mas_make ... [Label1 mas_makeconstraints:^ (Masconstraintmaker * Make) { = Uiedgeinsetsmake ( ); Make.edges.equalTo (Self.view). insets (insets); }];
The above code initializes a control object Label1 and adds Label1 to the Self.view
Call Mas_makeconstraints by object .... Method
Make in block stands for Label1 this control
Deges indicates the inner margin
Equalto (parameter) parameter to write is the reference view
Insets indicates the specific numeric parameter typeabove (uiedgeinsets type) initialization method as above make specific (top, left, bottom, right)
As you can see in the block method, we call the following in the form of point syntax to enumerate the various properties of make
Make.top.equalTo (parameter). offset (value) [offset is a number of offsets and many of these offsets are not written when the offset is 0]
Parameter values can be two types for a specific control, a view object such as a label, or a control, the upper and lower left and right position of the view
[Label4 mas_makeconstraints:^ (Masconstraintmaker * make) { // The bottom of a view is Mas_bottom/ / make.top.equalTo (label3.mas_top). offset (+); Make.top.equalTo (Label3.mas_bottom). Offset (+); Make.leading.equalTo (label3.mas_leading); Make.trailing.equalTo (label3.mas_trailing); Make.height.mas_equalTo (+); }];
In the code above, LABEL3 is the reference view (color is yellow), Label4 is constrained view (color is purple)
1. How to determine the positive or negative value of offset
Make.top.equalTo (label3.mas_bottom). Offset (+);
This code means that the bottom (maximum y value) distance of Label4 (maximum x value) relative to Label3 is 20
The judging method in the diagram refers to the position of the view label4. On the position of the constrained view label3. The direction of the pull arrow is the same as the Y axis, so the value of offset is positive
Also as when the reference view is Self.view, there is a label constrained view when the requirement is the right side of the label Self.view 20
Now we are from Self.view (the far right of the screen) like the Zola arrow to the right of the label and we find that the arrow direction is opposite to the x-axis, so the offset value is negative.
The code is make.right.equalTo (self.view). Offset (-20);
2. Below I have compiled some of the specific properties of make "/" to indicate that you can use either of these
Make.top/left/right/bottom.equalto (View object/View object up or down) view object up or down so that means View1.mas_top/left/right/bottom
The mas_top rules of Understanding are Equalto (the attributes of Mas_ modifiers)
View1.mas_top This is written in the Equalto () brackets (the top and bottom of the View object) Note Be sure to use the. Mas_top property instead of the.
Mas_equalto the way to use the width
Make.height/width.mas_equalto (Specific value)
The specific make attribute
Make.leading/trailing. Equalto (label3.mas_leading) (Mas_ modified property inside) indicates that the constrained view is left-justified/right-aligned with the reference view
// on the same size as the constrained view width is shorter than the reference view width 20 height Long 40 note the value here is up to 20 higher than thereference view, which is shorter than the reference view (Label1). Sizeoffset ( Cgsizemake (-+));
Uiedgeinsets insets = Uiedgeinsetsmake (+); Make.edges.equalTo (Self.view). insets (insets);
Edges
How to use Mesonry