I have two UILabels side by side in a row.Left label autolayout with its text and right label's width base on left label.
Code will be shown below.
UIView *preView;
NSArray *titleArray = @[@"abc",@"abcd",@"abcde",@"abcdefg"];
for (int i = 0; i < titleArray.count ; i ++) {
UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor blueColor];
label.font = [UIFont systemFontOfSize:15];
label.text = titleArray[i];
[self.view addSubview:label];
UILabel *valueLabel = [[UILabel alloc] init];
valueLabel.backgroundColor = [UIColor redColor];
valueLabel.font = [UIFont systemFontOfSize:15];
valueLabel.text = @" ";
[self.view addSubview:valueLabel];
preView = label;
[label mas_makeConstraints:^(MASConstraintMaker *make) {
if (i == 0) {
make.top.equalTo(@50);
}else
make.top.equalTo(preView.mas_bottom).offset(10);
make.left.equalTo(@10);
}];
[valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(label);
make.left.equalTo(label.mas_right).offset(10);
make.right.equalTo(@-10);
}];
}
It's under my expectation except row 1st. Could somebody know how to make it work?
Any help will be appreciated.