该结构是一个内部带有标签和文本字段的视图。 我需要在标签中使用不同字体大小的不同设备,并且根据标签的宽度,文本字段的宽度非常灵活。下面UITextFiled和UILabel布局失败,砌体结构失败
代码:
UIView *selectBgView = [[UIView alloc] init];
selectBgView.backgroundColor = [UIColor redColor];
[condiView addSubview:selectBgView];
[selectBgView makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@200);
make.height.equalTo(@20);
make.left.equalTo(@10);
make.top.equalTo(@20);
}];
UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:13];
label.text = @"Type :";
[condiView addSubview:label];
[label makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(selectBgView);
}];
UITextField * textField = [[UITextField alloc] init];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:13];
[condiView addSubview:textField];
[textField makeConstraints:^(MASConstraintMaker *make) {
make.right.top.bottom.equalTo(selectBgView);
make.left.equalTo(label.right);
}];
它并不像下面的图片工作。
但是,当我以期交换文本框。有用!
UIView *view = [UIView new];
view.backgroundColor = [UIColor greenColor];
[condiView addSubview:view];
[view makeConstraints:^(MASConstraintMaker *make) {
make.right.top.bottom.equalTo(selectBgView);
make.left.equalTo(label.right);
}];
如果有人可以帮助我!任何帮助将不胜感激。
我使用故事板并设置相同的常量,它工作得很好... – Lucifron
代码如何?它工作吗? – Yan