multipliedBy(約束值為約束對象的百分比)用法:
//button的寬度奔穿,占屏幕寬度的一半
[button1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.top.equalTo(self.view).offset(100);
make.width.equalTo(self.view.mas_width).multipliedBy(0.5);
make.height.equalTo(@100);
}];
Paste_Image.png
動態(tài)布局,根據(jù)內(nèi)容的大小帜讲,父視圖大小根據(jù)子視圖大小改變
Paste_Image.png
-(void)testLabelNumberofLines{
UIView*bgView0 = [[UIView alloc]init];
bgView0.backgroundColor = [UIColor redColor];
[self.view addSubview:bgView0];
[bgView0 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(100);
}];
UIView*bgView = [[UIView alloc]init];
bgView.backgroundColor = [UIColor yellowColor];
[bgView0 addSubview:bgView];
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(bgView0);
make.top.equalTo(bgView0).offset(20);
make.bottom.equalTo(bgView0).offset(-20);
}];
UILabel *label = [[UILabel alloc]init];
label.text = @"共勉吧,在iOS 7中椒拗,蘋果引入了一個新的屬性,叫做[UIViewController setEdgesForExtendedLayout:]获黔,它的默認值為UIRectEdgeAll蚀苛。當你的容器是navigation controller時,默認的布局將從navigation bar的頂部開始玷氏。這就是為什么所有的UI元素都往上漂移了44pt堵未。";
[bgView addSubview:label];
label.backgroundColor = [UIColor grayColor];
label.numberOfLines = 0;
[label sizeToFit];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(bgView);
make.top.equalTo(bgView.mas_top).offset(20);
make.bottom.equalTo(bgView).offset(-20);
}];
}
//相對于父視圖邊距為10簡潔寫法
UIEdgeInsets使用
-(void)testUIEdgeInsets{
UIView *view0 = [UIView new];
view0.backgroundColor = [UIColor grayColor];
[self.view addSubview:view0];
[view0 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(100);
make.centerX.equalTo(self.view);
make.height.equalTo(@100);
make.width.equalTo(@100);
}];
UIView *view1 = [UIView new];
view1.backgroundColor = [UIColor redColor];
[view0 addSubview:view1];
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(view0).insets(UIEdgeInsetsMake(10, 10, 10, 10));
}];
}
Paste_Image.png
// priority的使用
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.greaterThanOrEqualTo(self.view.mas_left).with.priorityLow();
make.top.equalTo(self.view.mas_top).with.priority(600);
}];