Laying Out a UIScrollView in Interface Builder

rmayoff · 60K views · 2013 · 11:00

Open on YouTube

Software (other)Software practice, open source & careerstutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when someone's UIScrollView won't scroll or size its content correctly in Interface Builder, especially with Auto Layout.

Recommended by 7 people across 9 different months, 2013 to 2015.

What it is

A short screencast by Stack Overflow user rob mayoff showing how to lay out a UIScrollView in an Xcode xib or storyboard, covering both springs-and-struts and Auto Layout approaches. It walks through the setup step by step in Interface Builder.

What people said

Strong rec Andy · 2015-03 · Stack Overflow · on “Swift - UIScrollView Scrolls Partially”

I know working with scrollviews are a pain. Most of the time to get them to work properly you will have to programmatically adjust constraints. Also, have you looked into setting/adjusting the `UIScrollView.contentSize` at runtime? One more thing. Please watch this video all the way through. It helped me TONS with scrollviews: [this video]

Recommends rob mayoff · 2013-06 · Stack Overflow · on “How to add objects to a UIScrollView that extend beyond UIView from Storyboard?”

UPDATE I have posted a screencast that walks through this technique step-by-step [this video] . ORIGINAL The easiest way to handle this is simply to make the view in your storyboard taller. When the app runs, any of the normal container view controllers ( UINavigationController , UITabBarController , UISplitViewController , or even UIViewController when it's the root view controller of its window) will resize the view to fit on the screen and scroll. Here's an example of how to set it up in Xcode: [LINK] I changed the view controller's size from “Inferred” to “Freeform”. Then I changed its view's height from 460 to 800. (By the way, control-shift-click gives you a menu of all objects under the cu

Recommends erdekhayser · 2013-09 · Stack Overflow · on “UIScrollView Scrollable Content Size Ambiguity”

Try placing the UILabel in a content view, then setting the trailing edge of the label to the content view (regular UIView). This video may help you greatly: [this video]

Recommends erdekhayser · 2013-09 · Stack Overflow · on “IOS7 : UIScrollView offset in UINavigationController”

Seeing your previous edit, I just discovered your issue. Unfortunately, it is not the most obvious solution. Rather than trying to explain it all over again, I used this video on Youtube to learn how to set up scroll views. [this video] Good Luck. It took me a couple times to watch it to fully understand what he is doing.

Recommends rob mayoff · 2013-11 · Stack Overflow · on “How do I retain layout integrity when using UIScrollView in Storyboard?”

You need to have at least one constraint between the top edge of the scroll view and one of its subviews, and at least one constraint between the bottom edge of the scroll view and one of its subviews. Auto layout will use these constraints to set the content size of the scroll view. You can find more information in Tech Note TN2154: UIScrollView And Autolayout [LINK] . You might also find my screencast about scroll views in Interface Builder [this video] helpful.

Recommends djibouti33 · 2013-12 · Stack Overflow · on “ScrollView doesn't scroll when I select the auto-layout option”

Autolayout and scrollViews are a special case. Wrap your scrollView in a UIView (call it contentView for example) and set the bottom constraints from the scrollView to its parent. The OS will figure out the rest. This is a pretty good demo video about your exact problem. Autolayout examples are towards the end: [this video] Also, here's a Tech Note from Apple: [LINK]

Recommends JetSet · 2014-01 · Stack Overflow · on “Can't scroll to the bottom of UIViewController XCode 5 Interface Builder to edit or add object below the fold”

This is the best way to resize UIViewController and incorporate the UIScrollView. Laying Out a UIScrollView in Interface Builder: [this video]

Recommends Mike Kogan · 2014-04 · Stack Overflow · on “iOS Invisible Spacer View?”

OK I figured it out. For what I wanted to do springs and struts and embedding the pieces I wanted centered in subviews was a ton easier than using autolayout at all. This reference helped me immensely [this video]

Recommends dev4life · 2014-08 · Stack Overflow · on “UIScrollView contentSize not working”

I used to do set up the uiscrollview programmatically UNTIL I watched the following wonderful tutorial, step by step how to get uiscrollview and uiview to work: [this video] After watching the video you will start liking Interface Builder I am sure. Vote up

Recommends rob mayoff · 2014-09 · Stack Overflow · on “Why is UIScrollView contentSize ignored in IB but works when I set it in my viewDidAppear method?”

I assume you have autolayout enabled for your storyboard (or xib). Auto layout sets the scroll view's contentSize based on constraints between the scroll view and its subviews. I believe this happens in the scroll view's layoutSubviews method. Methods are called in this order: view controller's viewDidLoad view controller's viewWillAppear: view controller's viewWillLayoutSubviews each view's layoutSubviews, from the root view down view controller's viewDidLayoutSubviews view controller's viewDidAppear: When you tried setting contentSize in viewDidLoad and in viewWillAppear: , it didn't work because the scroll view's layoutSubviews overrode it later. When you set it in viewDidAppear: , you ov