Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Storyboard: how do you edit a content view larger than screen in a UIScrollView

I have a view that is larger than screen, I need to put it in a UIScrollView.

So I first add an UIViewController to story board, then, I add a UIScrollView to the root view of my view controller, then when I add subviews of UIScrollView, but I can't add them outside the scrollview area I can see, how to solve this problem?

like image 321
CarmeloS Avatar asked Sep 05 '14 09:09

CarmeloS


2 Answers

Change the simulated size of the view controller to Freeform and then you can set the size to whatever you want. After editing, you may want to set it back.

freeform

like image 115
Collin Avatar answered Oct 20 '22 18:10

Collin


Edit 1:

1) put your subview into scrollview's visible area

2) change frame of the new subview as you wish

change frame

3) change contentSize property of scrollview with runtime attributes

runtime attributes

Edit 2: u can create a new view with xib, which contains all your subviews, and then add this view on scrollview OR u can use storyboard's Container View like this:

enter image description here

p.s.: don't forget about contentSize (point 3 in my first edit), but if you are using auto-layout, you need to set it programmatically like this:

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    _scrollView.contentSize = CGSizeMake(320, 250);
}
like image 26
aquarium_moose Avatar answered Oct 20 '22 19:10

aquarium_moose