我有一个UIView容器,它对超级视图有左/顶/右限制。所以尺寸是动态的,除了高度。 它没有底部约束swift:根据内部约束调整UIView高度
此视图包含内容(标签等)。这些元素也有相对于彼此和所述超级视图约束(证明EM)
的Label1
- > Label2.top:Label1.bottom(+左和上海华的右侧)
Label2的
- > Label3.top:Label2.bottom(+左和上海华的右侧)
LABEL3
等。
标签有动态尺寸,所以我无法确定标签的高度是多少。它使用属性字符串。所以计算子视景rects是不是解决方案
我想实现的是设置适当的高度的主要容器考虑约束 我厌倦了谷歌搜索,我得到的是一些帧矩形手动计算,其中不工作有限制。
这是内部因素的制约:
self.view.addConstraint(NSLayoutConstraint(
item:self.view, attribute:.Trailing,
relatedBy:.Equal, toItem:label,
attribute:.Trailing, multiplier:1, constant:0))
// left
self.view.addConstraint(NSLayoutConstraint(
item: label, attribute:.Leading,
relatedBy:.Equal, toItem:self.view,
attribute:.Leading, multiplier:1, constant:0))
// Top
self.view.addConstraint(NSLayoutConstraint(
item:parentView, attribute: positionConstraint,
relatedBy:.Equal, toItem:label,
attribute:.Top, multiplier:1, constant:0))
请帮助我!