【发布时间】:2014-11-21 04:19:42
【问题描述】:
我有一个 UIView 容器,它对超级视图有左/上/右约束。所以尺寸是动态的,除了高度。 它没有底部约束
这个视图里面有内容(标签等等)。这些元素也对彼此和超级视图有约束(以证明 em)
标签1
-> Label2.top : Label1.bottom (+superview的左右)
标签2
-> Label3.top : Label2.bottom (+superview的左右)
标签3
等等。
标签具有动态大小,因此,我无法确定标签的高度。它使用属性字符串。所以计算子视图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))
请帮帮我!
【问题讨论】:
标签: ios swift uiview constraints height