let innerView = UIView(frame: .init(x: 0, y: 0, width: 50, height: 50))
let outerSV = UIStackView(arrangedSubviews: [innerView])
outerSV.frame.width // still 0! should be 50
outerSV.frame.height // still 0! should be 50
那么問題來了:添加子視圖后如何更新stackView的大小?
uj5u.com熱心網友回復:
您應該在 stackView 的子視圖上呼叫sizeToFit()和layoutIfNeeded()。像往常一樣約束 UIStackView,并像往常一樣約束子視圖。
此外,您需要將其設定為按比例填充,它會調整大小以適應新內容。
并確保您在堆疊視圖上沒有高度約束的底部約束。您應該只需要左、右和上約束。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/372682.html
