iOS/Swift: Dynamically size UIStackView when one of its items gets larger
Solution 1
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.
Solution 2
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.
Solution 3
I had this on iOS 12, while it was working fine on iOS 13. Just set:
stackView.distribution = .fillProportionally
Fixed it :)
Solution 4
you one need to fill proportionally and it will work according to your code
jshapy8
Using software to solve problems. Currently doing it with iOS apps written in Swift.
Updated on July 09, 2022Comments
-
jshapy8 almost 2 years
I have two items in a vertical
UIStackView
: aUILabel
and aUITableView
. When a dynamic amount ofUITableViewCell
s get added to theUITableView
at runtime, theUIStackView
does not get larger.Is there a general way to increase the size of the
UIStackView
?