Reputation: 453
I have added a lot of ui elements in my controller and I have also done the web service part in the implementation code. It seems like my default screen size view controller is not sufficient for me to display the information. Is it possible to add a scroll view to the existing controller and if yes please give an idea or an example, so that I can add some more ui elements.
Thanks in advance.
Upvotes: 2
Views: 3413
Reputation: 1297
Try this to make the main view a scrollview:
- (void)loadView {
// create and configure the scrollview
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.view = scrollView;
}
loadView
is the method where the subclassed View Controllers should configure their main view, it is called automatically before the VC loads and shouldn't be called directly.
After adding all the elements to the scrollview you want to change the content size so it actually scrolls with something like this:
// this for a horizontal scroll
[scrollView setContetSize:CGSizeMake(CGRectGetMaxX(lastElementOnTheRight), scrollView.frame.size.height)];
// this for a vertical scroll
[scrollView setContentSize:CGSizeMake(scrolView.frame.size, CGRectGetMaxY(lastElementOnTheBottom))];
Upvotes: 2
Reputation: 137
Select the view you want to add to scroll view and then go to edit->embed in->scroll view.
Upvotes: 1
Reputation: 2894
You should get the scrolling behavior by default in a view Controller through inheritance. You may find this diagram helpful for future reference: uikit classes.
Additionally, you can add a scrollview to a view as such:
[self.view addSubview:scrollView];
Upvotes: 0