2015-10-19 85 views
1

我有一個需要並排佈局兩個UILabels的自定義單元。兩個標籤的寬度都是動態的,可以換行。不能在動態寬度的Tablecell中並排AutoLayout兩個UILabels

我已經定義的自動版式下下列情況

  1. 滾動的細胞和包含它的部分,所以,這是所有在屏幕上失敗。
  2. 將設備旋轉到橫向(需要足夠大的視圖才能顯示單元格)
  3. 向後旋轉,左側標籤將被壓縮。

如果整個細胞和含科不上輪換佈局之前屏幕不會失敗

這裏有幾個工作呢截圖和旋轉後

enter image description here

enter image description here

這與以下約束佈局

this.ContentView.AddConstraint(
    NSLayoutConstraint.Create(
     this.TextLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Left, 
     1.0f, (nfloat)LeftRightPadding)); 

this.ContentView.AddConstraint(
    NSLayoutConstraint.Create(
     this.TextLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Top, 
     1.0f, (nfloat)TopAndBottomPadding)); 

this.ContentView.AddConstraint(
    NSLayoutConstraint.Create(
     this.TextLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Bottom, 
     1.0f, 0 - (nfloat)TopAndBottomPadding)); 

this.ContentView.AddConstraint(
    NSLayoutConstraint.Create(
     this.DetailTextLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Right, 
     1.0f, 0 - (nfloat)LeftRightPadding)); 

this.ContentView.AddConstraint(
    NSLayoutConstraint.Create(
     this.DetailTextLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Top, 
     1.0f, (nfloat)TopAndBottomPadding)); 

this.ContentView.AddConstraint(
    NSLayoutConstraint.Create(
     this.DetailTextLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Bottom, 
     1.0f, 0 - (nfloat)TopAndBottomPadding)); 

this.ContentView.AddConstraint(
    NSLayoutConstraint.Create(
    this.DetailTextLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.TextLabel, NSLayoutAttribute.Right, 
     1.0f, 
     10)); 

如何阻止擠壓左側標籤?

+0

增加左壓縮阻力? –

回答

2

增加到高於750

UILabels的內容擁抱優先最初,內容擁抱和內容壓縮阻力的優先級將像的下方。

enter image description here

設定值如下

enter image description here

任何值可以設置到這些,而是​​根據你的優先權。

+0

我想你是指圖像中的「Content Compression Resistance Priority」。 – Markus

+0

我以前試過壓縮阻力。我會嘗試擁抱和抵抗現在 –

+0

你說「750以上」,但他們在圖像設置爲750。 750夠了嗎? –

相關問題