I've been having such a hard time with this issue for the past 2 days. The structure I'm looking for is as follows:
- I want to have a scroll view take up the entire screen so that it's scrollable vertically.
- I want the image view to be added at the top of the scroll view and a vertical stack view to be added to below.
The key point is for the vertical stack view to increase in its height dynamically depending on the content.
First, I just tried adding the stack view without the image view just to test out the dynamic scrollable height. Followed the SO answer from here:
- Added the scroll view with 0, 0, 0, 0 constraints.
- Added the stack view to the scroll view. Set the constraints to the
Content Layout Guide
, 0, 0, 0, 0 constraints. - Set the width of the stack view to be equal the scroll view.
This gave me a constraint error saying I need to set a fixed height for the scroll view. Adding the constraint doesn't let me scroll. I tried pinning the stack view to the scroll view directly, and not to the Content Layout Guide
, but still doesn't work.
I followed Apple's documentation on the scroll view and added a content view within the scroll view before pinning the stack view to the content view:
This doesn't scroll either.
The stack view's distribution was either set at equal spacing or fill.
Please help.