user1511244
user1511244

Reputation: 725

How to make a view controller scrollable?

I have a view controller on which i parse data from a server and show on screen an article. Now the article can have any size from 10 characters to 10000. So what i need is to make the whole view controller scrollable to the user so he can scroll trough the whole article. How can i do that? Can it be done only through the IB? On my view controller i have images and labels to show the articles data.

Or maybe its easier to make only the label that i keep the main articles text scrollable and not the whole controller?

Upvotes: 0

Views: 2625

Answers (1)

h4cky
h4cky

Reputation: 894

You must extend UIScrollView by your own class or can alloc/init it.

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size. height)];
scrollView.backgroundColor = [UIColor clearColor];
[scrollView addSubview:otherView];

scrollView.contentSize = scrollView.frame.size;

[self.view addSubview:scrollView];

after that you must add views to the scrollView and set properly contentSize

Upvotes: 2

Related Questions