jake9115
jake9115

Reputation: 4084

How to modify a view in my storyboard to support scrolling in Xcode?

I am in the middle of making an iPhone app. I have a storyboard with several views. One of these views has a lot of content that fills the whole iPhone 5 screen with no room to spare. I want to make this screen scroll for older iPhone 3.5" screens. Does anyone know of a simple way to do this? I tried just changing the UIView class to UIScrollView, but that didn't seem to do anything.

Any suggestions are much appreciated!

Upvotes: 1

Views: 79

Answers (3)

Vaisakh
Vaisakh

Reputation: 1088

Try this. Let your view be 'contentView'

Add this code to viewDidLoad in .m file.

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[scrollView addSubview:contentView];
scrollView.contentSize = contentView.frame.size;
[self.view addSubview:scrollView];

OR

Just drag and drop a UIScrollView in your xib file and put your view inside that scrollview. Then in code viewDidAppear just set the contentSize of scrollview.

scrollView.contentSize = contentView.frame.size;

If you need scrollview fill whole screen set the frame of scrollview just before setting contentSize

scrollView.frame = self.view.bounds;

Edit : Just drag and drop a UIScrollView to your ViewController and arrange like this.

enter image description here

Upvotes: 2

bhavya kothari
bhavya kothari

Reputation: 7474

Put all your content in your scrollView from the beginning
and put below code in your viewDidLoad

if ([UIScreen mainScreen].bounds.size.height == 480) {

     self.scrollViewMain.contentSize = CGSizeMake(320, 2000);
}

Upvotes: 2

jayraj m.g.
jayraj m.g.

Reputation: 625

set scrollview content size for enabling scrolling of your scrollview.

you can set it directly from scrollview property from XIB or do it programatically.

Upvotes: 0

Related Questions