2014-09-26 265 views
0

我有一個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)) 

請幫助我!

回答

相關問題