How to add objects to a UIScrollView that extend beyond UIView from Storyboard? How to add objects to a UIScrollView that extend beyond UIView from Storyboard? ios ios

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.

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:

xcode procedure for resizing a storyboard view

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 cursor.)

Here's what happens when I run it in the simulator:

simulator running the example app

As you can see, the view hierarchy was resized to fit the screen, but the subviews of the UIScrollView weren't repositioned, and the scroll view set its content size appropriately. (That may only work properly with autolayout, though...)


So, an example to you how to add a Button:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];[btn setTitle:@"Cool title" forState:UIControlStateNormal];[btn setFrame:CGRectMake(50, 700, 100, 100)];[btn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];[_scroller addSubview:btn];

You just need to set the frame of the view that you want to add and after that add it as a subview in your scroll.


You can you use the Size inspector(Left part of xcode) in order to position it. or reposition it programmatically.

Cheers,Kel