Scroll views + Auto Layout in XIB: ambiguous scrollable content width

I have the following, simple layout: just a scroll view, with some views in it (please excuse the preview screenshot, since I’m using XIBs, there is no way to zoom out):


Here is my view hierarchy + constraints (the vertical constraints are all set up, throughout the view):


My problem with this case is that I get the following error in Interface Builder:


I’ve read up on the issue, I’ve found that I would need to add my scroll view as a subview to a simple view to silence this warning, but couldn’t make it work (the view didn’t scroll for some reason).

I think I understand the error here: the scroll view doesn’t know, how far it can scroll horizontally, but I’ve found no way to specify this in IB (instead of setting it to a concrete value – which I don’t want).

The problem is even more obvious, when I try to add another view to my hiearachy, and constrain its leading, trailing, and bottom edges to the scroll view:


The view just can’t figure out its width, thus the messed up scrolling.

My question is the following: is there a good way to get rid of this ambiguity? In Storyboards, you can just add equal height/width constraints to the root view, but this is not an option with XIBs.

Source: ios

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.