0
votes

I want to set the content view of a scrollview to whatever the current screen size is, but AutoLayout is doing some funky stuff. This is trivial in code... just create a scrollview with a frame that is the superview's bounds. Then create a content view with the scrollview bounds and populate it and set the alwaysBounces... properties to YES. In interface builder though, this is some kind of sinful thing it seems.

I know Autolayout handles scrollviews totally differently because it wants to infer the content size based on constraints. My approach that failed is setting the scrollview to have 0 distance to its superview (all sides attached). Then, the same with the content view (the single scrollView subview)- attached to all superview edges. Then the precompiler thing complains about not knowing the content size, so I set a width and height constraint at placeholder to be removed at build time. But the result is a (CGRect){0,0,0,0} contentView. The 0 space to trailing edge and bottom of superview are totally ignored.

So how can I make a scrollview with a dynamic content size based on the screen size?

Bonus points if you can explain how you would do the same, but for a content size of 2x screen width.

1

1 Answers

1
votes

You can try setting a constraint for the content view's width to equal the scroll view's width (for your bonus question: with a multiplier of 2). Same for height.

Not sure what the point of having a scroll view whose content is always the size of the scroll view is. By definition it wouldn't scroll, right?