I have created a fresh View Controller, then added a Scroll View as child of the root View, and set "Leading/Top/Trailing/Bottom Space to Superview" to 0 so that the scroll view would fill its parent completely.
Then I added a button as child of the scroll view, with space constraints of 15 to "Superview" (i.e. to the scroll view). I would thus expect the button to have a spacing of 15 to top/left/right borders, and the scroll view's content to end at 'bottom of button + 15'. However the width of the button is not correct (tested within Xcode 5 Interface Builder, iOS 6/7 simulators):
It doesn't even work if I constrain the button with "Equal Width to Superview"! Still doesn't take up the full width.
How do I solve this?
Found a good solution :) The reason for this behavior is that the scroll view adapts its content view size to what is actually needed by its subviews, and won't fill width/height automatically. If width should be filled, the scroll view thus must contain at least one view that fills the width of the screen.
With these steps, I added a view that has equal width to the scroll view (the scroll view itself, not its content view area), leading to my scroll view finally expanding to the full width because I had also added constraints "space to superview 0/0/0/0" to the scroll view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With