I have all my controls laid out in interface builder (many labels, buttons etc). How do I put them all in a scroll view in interface builder so that I can have more space and be able to scroll up and down to reveal more controls? Do I have to do this programatically?
Open the view that has all the controls and labels, etc. (in Interface Builder). Select All. Then under the Layout menu, select Embed Objects In... (scroll view). |
|||||||||||||||||||||
|
My preferred solution, where you don't need to hard-code the size of the contentSize: NB: you might be able to avoid the source-code parts of this using the trick here: http://stackoverflow.com/a/11239123/153422 - although I haven't tried it yet. The rest of this trick ... you still need to use anyway
Code (StackOverflow won't let me put code inside a numbered list. Sigh) Header file:
Class file:
...although I haven't checked this recently, IIRC it works on both 2.x and 3.x |
|||||||||||||||||||||
|
Its easy: First add a scrollview to your view. Change the size of the scrollview (e.g. make it 700 pixels long). Start putting your controls When you want to put/edit controls in the lower (invisble) part, select the scrollview and change the Y-start position to -300. Voila. After editing set the Y-start position back to 0 or whatever it was. |
|||||||||
|
Select all the objects you want to put into a scroll view and go to the Layout menu, choose "Embed Objects In" and choose "Scroll View". |
|||
|
I don't know if it's just me, but I tried to follow the instructions in each of the other answers here and none of them worked. None of the answers included everything needed, each one I guess assuming we know to do something so leaving that part out. I finally figured it out with the help of red artisan. So... I am listing here ALL the necessary steps to get this to work:
Header File: @interface MyViewController : UIViewController @property(nonatomic, retain) IBOutlet UIScrollView *scrollView; @property(nonatomic, retain) IBOutlet UIView *contentView; Class File: @synthesize scrollView, contentView; - (void)viewDidLoad { [super viewDidLoad]; [self.scrollView addSubview:self.contentView]; self.scrollView.contentSize = self.contentView.bounds.size; } - (void)viewDidUnload { self.scrollView = nil; self.contentView = nil; [super viewDidUnload]; } |
||||
|
Although this question is very old, I will suggest a workaround I found as I had the same issue and wasn't able to find much help out there: When in IB, if you want to place objects outside the 420 pixel, just make sure yourself of having selected Unspecified for all of Status Bar, Top Bar, and Bottom Bar for the View that contains the Scroll View with all the objects. This way, you'll be able to manually resize the screen (for the View). Then, you can follow Ximonn's advice on resizing the H value for the Scroll View, having access to all the other objects, working with them and then, undoing changes for H value and then setting the needed Bars. |
|||
|
Important little thing. To scroll big subview (UIImageView for example) in UIScrollView remember, for this subview, uncheck "User Interaction Enabled" checkbox in InterfaceBuilder -> View window. Or do it programatically.
Otherwise this subview will stack on screen without any effect. |
|||
|
I've been looking for this for a few days, and I finally came across this site with a solution that worked for me. Basically you have your main view with a UIScrollView object in it. Then another content view with all your content in it. Then you add the content view to the scroll view. And then finally set the size of the scrollview's content size to the size of the content view. |
|||
|
I know, this thread is a bit older... But somebody could find it on google, it's hight ranked. I wrote this little helper Method to get the job done:
You just have to declare two IBOutlet's in the header (e.g.
I called it in viewDidLoad This method features iOS |
|||
|
The selected answer works well for Xcode 3. However, for Xcode 4, menus have been re-arranged slightly. To do the same in Xcode 4 select your views then use: Editor > Embed In > Scroll View |
|||
|