Akram Fares
Akram Fares

Reputation: 1683

Display items inside ScrollView on Storyboard

My problem is when i want to display multiple items inside a scrollview on Storyboard, i can't scroll to add more items because of the screen size of the View Controller. How can i get around this ?

Xcode version : 4.6 Autolayout : enabled

Here is what i want to do :

Example

EDIT : I found a workaround to this problem. Just add items with minimal height and then resize it in code.

Upvotes: 4

Views: 2880

Answers (4)

Bipin Patel
Bipin Patel

Reputation: 228

Try to beloved steps

Change size of ViewController Size

Change Size of View of ViewController

Add button

after add button resize of view(height=568) and Viewcontroller > Simulated Metrics > Size > inferred

Upvotes: 3

vikasgupta.iphone
vikasgupta.iphone

Reputation: 29

make scrollview object and set in viewDidLoad .

self.scrollView.contentSize = CGSizeMake(320, 960);

Use what height you want like: 960

Upvotes: 1

foFox
foFox

Reputation: 1124

There is a way. Might seem difficult but its actually quite easy. It's a hybrid solution, with storyboard and nib file. You have to build a view inside a nib file instead of a storyboard.

1) Create your view controller named, let's say, "MyViewController".

2) Create a nib file, named "MyViewController" (name of a viewcontroller and nib file must match for this trick to work).

3) Go to that nib file, you created, drag a scroll view from object library.

4) Look at the side menu, and search for "File's Owner" icon (empty cube), Under identity inspector Change the file's owner to the view controller you created, "MyViewController".

5) Right click on the file owner and a menu will pop up, control drag, from the view connection to the scroll view you dragged from object library.

6) Click on the scroll view you just dragged, and go to the attributes inspector. Under "Simulated Metrics" change "Size" from "Retina 4 Full Screen", or whatever it happens to be, to "Freedom".Now you can drag bottom edge of the scroll view down, to make enough room for all the subviews. Make sure you don't accidentally increase the width.

7) Go back to the storyboard.

8) If the view controller is not created, drag it from the objects library. Change its class to "MyViewController".

9) Now this is where the trick is gonna happen. Make sure you delete ALL views from that view controller, including the background view. If you do that correctly you will be able to see the grid background of the interface builder. This forces the storyboard to look for a nib named the same as the view controller.

10) Run, and smile (Make sure that you add some subviews to the scroll view, that are off the bounds of a single screen, so you must scroll to see them, otherwise it wont set the contentSize correctly, and you wont be able to scroll ) :)

Upvotes: 2

Marcin Kuptel
Marcin Kuptel

Reputation: 2664

I don't think it is a very practical way to do it in IB. A better approach would be to do it in code.

Upvotes: 0

Related Questions