jake9115
jake9115

Reputation: 4084

Adding a UIScrollView to an existing view with lots of objects... how to easily make whole view scrollable?

I made an app that has a lot of content on its view (images, buttons, text labels, etc.) and is optimized for the iPhone 5 display. However, the part of the view that is missing when viewed on an iPhone 4 screen is just additional settings, and is perfectly acceptable to be hidden until scrolled to.

So, how do I made my entire view scrollable for iPhone 4 users? I tried just dragging and dropping a UIScrollVIew object over the top of the whole view, but it doesn't add scrolling capability.

I have worked with UIScrollView before, but it was always something I added to the view before anything else, and don't know how to go about adding it to my view now that there are already bunches of objects. Hopefully there is some easy solution that doesn't require manually addig every object as a subView, etc.

Thanks for the suggestions!

Upvotes: 3

Views: 1976

Answers (2)

Andrea
Andrea

Reputation: 143

From the InterfaceBuilder you can select all your content views (images, buttons, text labels, etc.) and then select Editor > Embed in > ScrollView.

enter image description here

This will create a UIScrollView containing al the views selected.

WARNING: you will lose all constraints between these subviews and the superview or the layout margin. Relative constraints (from subview to subview) will remain.

This approach is very useful when you wan to make only some content scrollable.

Upvotes: 3

nevan king
nevan king

Reputation: 113767

I don't know how your views are created, but the easiest thing would be to change the class of the main view from UIView to UIScrollView.

Upvotes: 3

Related Questions