Reputation: 1427
I need to create a long uiscrollview with bunch of subviews embedded inside. However, Storyboard gives me too small area to work with when I add an uiscrollview to a controller. Is there a way to work on uiscrollview first and add it to the controller later using storyboard?
Like the #2 on this tutorial page (it's not storyboard ver.) : http://agilewarrior.wordpress.com/2012/05/18/uiscrollview-examples/
The version is 4.5.2.
Thank you!
Upvotes: 1
Views: 2160
Reputation: 438027
With storyboards, you can't drag a control out of the scene, but you can probably achieve what you want by changing the simulated metrics of the scene itself. So select the view controller itself and click on the "Attributes inspector", and change the simulated size metric to be free-form, as highlighted here:
Then click on that scene's main view and open the "Size inspector" for that, and change the size to be something big enough to work:
Your storyboard will look strange, but you can now add/alter your scrollview so it's big enough to show everything you want on it. Once you run the app (assuming you have set your autolayout constraints or non-autolayout autosizing masks properly), it will work fine:
Curiously, I found that when not using autolayout that I did have to programmatically change the contentSize
of the scrollview, though, to make sure it was big enough for all of the controls:
- (void)adjustContentSizeForScrollView:(UIScrollView *)scrollView
{
CGFloat height = 0.0;
for (UIView *subview in scrollView.subviews)
{
CGFloat viewBottom = subview.frame.origin.y + subview.frame.size.height;
if (viewBottom > height)
height = viewBottom;
}
scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, height);
}
Upvotes: 4