場景1:4個label等寬占滿整個屏幕寬
//四個label等寬
{
UILabel *label1 = [[UILabel alloc] init];
label1.backgroundColor = [UIColor redColor];
UILabel *label2 = [[UILabel alloc] init];
label2.backgroundColor = [UIColor yellowColor];
UILabel *label3 = [[UILabel alloc] init];
label3.backgroundColor = [UIColor orangeColor];
UILabel *label4 = [[UILabel alloc] init];
label4.backgroundColor = [UIColor blueColor];
[self.view addSubview:label1];
[self.view addSubview:label2];
[self.view addSubview:label3];
[self.view addSubview:label4];
[label1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(300);
make.leading.equalTo(self.view);
make.height.mas_equalTo(100);
// make.width.mas_equalTo(100);
}];
[label2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(label1.mas_right );
make.height.equalTo(label1.mas_height);
make.top.equalTo(label1.mas_top);
make.width.equalTo(label1.mas_width);
// make.right.equalTo(self.view.mas_right);
}];
[label3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(label2.mas_right);
make.height.equalTo(label2.mas_height);
make.top.equalTo(label2.mas_top);
make.width.equalTo(label2.mas_width);
// make.right.equalTo(self.view.mas_right);
}];
[label4 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(label3.mas_right);
make.height.equalTo(label3.mas_height);
make.top.equalTo(label3.mas_top);
make.width.equalTo(label3.mas_width);
make.right.equalTo(self.view.mas_right);
}];
}
效果圖:場景2:3個lable 1.2等寬 3是1.2寬的2倍 2高是1.3的2倍,寬占滿整個屏幕
//三個控件,頭2個等寬第三個是前面寬的2倍,第二個高是其他2個的2倍
{
UILabel *label1 = [[UILabel alloc] init];
label1.backgroundColor = [UIColor redColor];
UILabel *label2 = [[UILabel alloc] init];
label2.backgroundColor = [UIColor blueColor];
UILabel *label3 = [[UILabel alloc] init];
label3.backgroundColor = [UIColor grayColor];
[self.view addSubview:label1];
[self.view addSubview:label2];
[self.view addSubview:label3];
[label1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(450);
make.leading.equalTo(self.view);
make.height.mas_equalTo(150);
}];
[label2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(label1.mas_top);
make.left.equalTo(label1.mas_right);
make.height.equalTo(label1.mas_height).multipliedBy(2);
make.width.equalTo(label1.mas_width);
}];
[label3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(label2.mas_top);
make.left.equalTo(label2.mas_right);
make.height.equalTo(label2.mas_height).multipliedBy(0.5);
make.width.equalTo(label2.mas_width).multipliedBy(2);
make.right.equalTo(self.view.mas_right);
}];
}