我正在问一个关于使用autolayout调整超级视图大小的问题!
首先,我在界面构建器中创建一个自定义单元格。单元格中只有一个高度为 0 的自定义视图。视图的顶部,底部,左侧和右侧方向都具有cell.contentView(view.superview)的约束。
然后,我在视图中启动两个标签,并为这样的标签设置文本:
- (void)customView
{ _title = [UILabel newAutoLayoutView];
_text = [UILabel newAutoLayoutView];
_title.numberOfLines = 0;
_text.numberOfLines = 0;
_title.backgroundColor = [UIColor greenColor];
_text.backgroundColor = [UIColor greenColor];
_title.text = @"this is the title";
_text.text = @"this is the text";
[_view addSubview:_title];
[_view addSubview:_text];
[_title autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:5.0f];
[_title autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:5.0f];
[_title autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:5.0f];
[_title autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:_text withOffset:-10.0f];
[_text autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:5.0f];
[_text autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:5.0f];
[_text autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:5.0f];
}
但是在运行时,结果会因布局错误而崩溃。虽然我认为超级视图会在设置标签文本时调整大小。我很确定布局是正确的。我认为这可能是错误的约束集的优先级。
有没有人遇到同样的问题?我很感激任何帮助。
注意:重要的一点是视图的高度为 0 !!!