主要屬性
@property (nonatomic, strong, readonly) MASConstraint *left;//左側(cè)
@property (nonatomic, strong, readonly) MASConstraint *top;//上側(cè)
@property (nonatomic, strong, readonly) MASConstraint *right;//右側(cè)
@property (nonatomic, strong, readonly) MASConstraint *bottom;//下側(cè)
@property (nonatomic, strong, readonly) MASConstraint *leading;//首部
@property (nonatomic, strong, readonly) MASConstraint *trailing;//尾部
@property (nonatomic, strong, readonly) MASConstraint *width;//寬
@property (nonatomic, strong, readonly) MASConstraint *height;//高
@property (nonatomic, strong, readonly) MASConstraint *centerX;//橫向中點(diǎn)
@property (nonatomic, strong, readonly) MASConstraint *centerY;//縱向中點(diǎn)
@property (nonatomic, strong, readonly) MASConstraint *baseline;//文本基線
術(shù)語解釋
- 必須先將視圖添加至父視圖(
[fatherView addSubview:View]
)级乐,才能進(jìn)行設(shè)置疙咸。 - 在Masonry中,and,with都沒有具體操作风科,僅僅是為了提高程序的可讀性撒轮。
make.left.and.top.mas_equalTo(20);
等價(jià)于
make.left.top.mas_equalTo(20);
- 設(shè)置距離數(shù)值時(shí),正數(shù)為向右的距離贼穆,負(fù)數(shù)為向左相距的距離题山。
- 如果約束條件是數(shù)值或者結(jié)構(gòu)體等類型,可以使用mas_equalTo進(jìn)行包裝故痊。
一般將數(shù)值類型的約束用mas_equalTo顶瞳,而相對(duì)于某個(gè)控件,或者某個(gè)控件的某個(gè)約束崖蜜,使用equalTo浊仆,如:
make.size.mas_equalTo(CGSizeMake(100, 100));
make.center.equalTo(weakSelf.view);
約束函數(shù)
添加大小約束(大小為100 *100)
make.size.mas_equalTo(CGSizeMake(100, 100));
居中約束
make.center.equalTo(weakSelf.view);
與左邊界約束(本視圖左側(cè)與父視圖邊界相切為0)
make.left.equalTo(self.view).offset(0);
與其他控件寬度約束(本視圖的寬度與其余兩個(gè)視圖寬度相等)
make.width.equalTo(@[topView,bottomView]);
設(shè)置兩個(gè)控件之間的距離(頂部與上一個(gè)視圖底部相距150)
make.top.mas_equalTo(topView.mas_bottom).offset(150);
與左、下均相切
make.left.bottom.equalTo(self.view).offset(0);
設(shè)置寬和高的約束(均為150)
make.width.height.mas_equalTo(150);
設(shè)置兩個(gè)控件關(guān)聯(lián)(該控件與目標(biāo)控件高度一致【縱坐標(biāo)相等】)
make.centerY.mas_equalTo(imageView1);