iOS開發 - Content hugging priority & Content compression resistance priority

來源:互聯網
上載者:User

標籤:

1. 什麼是Content hugging priority

你可以把它想象成一根放在視圖上的橡皮筋。

這根橡皮筋會組織視圖超過它本身的固有大小(intrinsic content size)。

它存在一個優先順序,從0到1000。

1000表示視圖絕對不能超過intrinsic content size。

我們來看個例子:

中有兩個橫向排列的標籤控制項(label),並且你也已經設定好了約束。

這個會工作正常,直到父視圖變寬的時候。

那麼,問題來了。

如果父視圖變寬了,那個label應該變寬呢?

這個時候正是我們用到Content hugging priority的時候。

擁有高優先順序Content hugging priority的視圖控制項將不會被展開。

你可以把這個優先順序想象成橡皮筋的抗展開力。

這個優先順序越大,視圖將越希望保持自己的固有大小(intrinsic content size)。

 

2. Content compression resistance priority

和Content hugging priority相反,Content compression resistance priority是用來抵抗壓縮的。

簡單的來說,前者我們討論過的,是抵抗展開,也就是抵抗變大,而後者是抵抗壓縮,也就是抵抗變小。

還是上面的例子中,當父視圖變小的時候,擁有高優先順序的label將不會被壓縮,因而標籤上的文本也就不會被截斷。

 

iOS開發 - Content hugging priority & Content compression resistance priority

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.