Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visually arrange subviews in a large UIScrollView

One of the screens in my app has to be vertically scrollable. Its contents is more or less static, but it doesn't fit on the phone's screen (hence the scroll view). I'm using a UIScrollController as a top view, and I'd like to use the storyboard editor in Xcode to lay out all the views in it. Can I do that? I can obviously drop things on the visible part of my UIScrollController, but can I put more views "below the fold" visually?

like image 498
TotoroTotoro Avatar asked Feb 15 '12 04:02

TotoroTotoro


1 Answers

There is another way to do it that is different from the answers given in the link in the comment above which I believe is easier because it allows you to see your whole content view at full size and design it in Storyboard.

  • 1)Place a UIScrollView as the root view of the controller.
  • 2) Click on the View Controller in storyboard and goto the Attribute Inspector and change the Size to Freeform
  • 3) Click on the Scroll View in storyboard and goto the Size Inspector and change the Width & Height to as big as you need. (2,000 x 4,000)
  • 4)Place a UIView as a subview of the scrollview, this will be your Content View where you will design your screen and put all your subviews. Don't forget to set the contentSize of the scrollview to the size of this view in viewDidLoad.
  • 5) Click on the UIView from #4 and in the Size Inspector set the Struts and Springs so this view is not resized enter image description here.
  • 6) Design the rest of the screen

The trick is in #3 & #5 setting the size of the scrollView to really large so you can design. When this viewController is loaded into the iPhone the Struts & Springs will resize the scrollView to the size of the iPhone screen, but the contentView will stay large.

like image 75
agilityvision Avatar answered Oct 20 '22 00:10

agilityvision