Question

Need some help to set constraints to UIScrollView.

I tried to follow the instructions here: https://developer.apple.com/library/ios/technotes/tn2154/_index.html (Mixed approach).

Setting 4 sided constraints to UIScrollView. Then set 4 sided constraints to the buttonContainer.

This the result:

enter image description here

However xcode is giving this error message:

enter image description here

If I try xcode's recommendation, either the scrollview will not scroll, or it doesn't display at all.

Any idea what's wrong here?

Was it helpful?

Solution

The messages you are getting tell you what to do. The scroll view sets its content size and becomes scrollable through the constraints pinning its subview(s) to the scroll view itself. Those constraints must therefore provide sufficient information. You have not provided enough internal constraints to describe the height and width of the scrollable area (the content size).

In other words, think of the constraints as sizing the buttonContainer from the inside out. That is what you have neglected to do. You can solve this, for instance, simply by giving the buttonContainer an absolute width constraint and an absolute height constraint. And those values need to be bigger than the size of the scroll view itself if the content is to be scrollable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top