user1420042
user1420042

Reputation: 1709

How can I add a UIScrollView to a View in an iOS app?

I have built a small iOS 6 app that uses a single view. However, I would like to add some more functionality and therefore need more space. I figured that the best way to do this is to add a UIScrollView.

How can I add such a UIScrollView to my View? Do I have to delete all my buttons, labels, etc. in my View, then add a UIScrollView and then put all those buttons, labels, etc. in that UIScrollView? I think that this would work but is there an easier way to do this? (Maybe without deleting all the content in my view)

Upvotes: 0

Views: 221

Answers (3)

shivam
shivam

Reputation: 1140

Add all views on scroll view like:

[scrollview addSubView:button];

And finally add this scrollview to main view:

[self.view addSubView:scrollview];

I think this will be helpfull. :)

Upvotes: 1

Shekhar Gupta
Shekhar Gupta

Reputation: 6218

Yes you can add a view to UIScrollView without deleting buttons, labels, etc..

To add a scroll view to existing view:

  1. Draw and drop the UIScroll View to the existing View
  2. Select all controls in the View like Buttons, Label etc.; except UIScroll View
  3. Drag all the selected component into UIScroll View

Let me know if you have any doubt.

Upvotes: 2

Retterdesdialogs
Retterdesdialogs

Reputation: 3210

programmatically you have to

[scrollview addSubView:button];

instead of [self.view addSubView:button];

In storyboard or xib you can drag and drop the button onto the scrollview.

Hope this helps a little bit.

Upvotes: 0

Related Questions