I am trying to wrap my head around UIScrollView with autolayout. I know this has been asked many times, but no solution has worked for me.
The view hierarchy is:
view (UIView)
- scrollView (UIScrollView)
- contentView (UIView)
- label (UILabel)
The constraints are (as suggested here and everywhere else):
scrollView:
- Leading space to container margin
- Trailing space to container margin
- Vertical spacing to top layout guide
- Vertical spacing to bottom layout guide
contentView:
- Leading space to container margin
- Trailing space to container margin
- Vertical spacing to container top margin
- Vertical spacing to container bottom margin
- Equal widths to "view"
(...that is, pinned all four sides to the scroll view and one dimension to the scroll view's superview).
This gives me the error:
Scroll View needs constraint for: height.
I further add the label inside the content view, and constrain its width, height, leading space and vertical space to container top (i.e., fixed size, and pinned to contentView
's top left corner).
However, it appears in a red frame, but no missing constraints suggested in the left pane (only that for the scroll view).
I add all the missing constraints anyway: with the red octagon button in the navigation pane -for the scroll view- and the "|-triangle-|" button at the bottom right (with the label selected)
When I launch the app, my layout appears briefly and then fades to white (the view controller's view background color).