iOS: Changing subclass from UIView to UIScrollView in a storyboard
You can open storyboard as an xml source code file, find view object and replace it with scrollview. Right-click on .storyboard
file in Xcode and choose Open As → Source Code. Then search for your scene's xml snippet (for example, Cmd+F and type controllers name). Top view object will look like this:
<view key="view" contentMode="scaleToFill" id="Jjm-HD-A8W"> ... (suviews and constraints) ...</view>
Change view
element to scrollView
(don't forget the closing tag):
<scrollView key="view" contentMode="scaleToFill" id="Jjm-HD-A8W"> ... (suviews and constraints) ...</scrollView>
Then open .storyboard
with the Interface Builder. Your view now became a scrollview.
This method has two advantages: you don't loose any constraints and you see all scrollview specific properties in the attributes inspector.
You have to change the UIView
type to UIScrollView
(identity inspector) and in the controller viewDidLoad
method assign the view a contentSize
by casting the view to a UIScrollView
:
[(UIScrollView *)self.view setContentSize:CGSizeMake(320, 700)];
There's actually a much better way to do this.
- Toggle open the
UIView
in the StoryBoard and cut to your clipboard anything inside it. - Delete the
UIView
. - Insert a
UIScrollView
object into your StoryBoard. - Paste from your clipboard into this new object.
This method will preserve all delegate and IBOutlet settings you've configured for the things inside the view.