[英]AutoLayout constraints to UITableViewCell contentView not respected
我正在嘗試創建動態調整表格視圖單元格。 我通過使用這個非常詳細和有用的答案完成了調整大小。
但是,在heightForRowAtIndexPath
未正確計算標簽的最大寬度。
我的單元格目前在其contentView
只有一個標簽,約束設置為將所有標簽邊緣固定到contentView
邊緣。 這就是我在IB中所擁有的
使用heightForRowAtIndexPath
的offscreen單元計算單元格大小
CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
在此過程中,似乎它正在label.preferredMaxLayoutWidth
約束,並且label.preferredMaxLayoutWidth
屬性被設置為320,但是當標簽實際被渲染時,仍然存在填充。
填充是布局邊距。 你必須要注意Constrain to margins
選項。
Constrain to margins
已啟用:
Constrain to margins
已禁用:
如何禁用它?
Relative to margin
選項: Constrain to margins
:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.