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
So the question is: how to update the size of stackView after adding subviews?
CodePudding user response:
You should call sizeToFit()
and layoutIfNeeded()
on the subviews of the stackView. Constrain the UIStackView as you normally would, and constrain the subviews as you normally would.
Also, you need to have it set to Fill Proportionally and it will resize to fit the new content.
And Make sure you don't have a bottom constraint of a height constraint on the stackview. You should only need left, right and top constraint.