If you have ever tried to design the content of a large view that is going to be in a UIScrollView for the iPhone you might have gotten stuck on how to do this without resorting to manual pain in the ass tricks like changing the x,y offset over and over. When trying to do the same thing an idea sprung in my head that required a bit of gestalt switch.
Above you can see there is a picture that is the contents of a scroll view and I would like to be able to see the whole contents and add some more subviews. What to do?
The answer came to be make the scroll view the same size as the containing content view. Now you can see the whole view and design to you hearts content. But it would be a real pain to have to remember to reset the size of the view controller everytime you wanted to do some editing or even just see what is in the scroll view. This is where the trick comes in. We are going to leave the UIScrollView set at this large size. What!?!?! You can’t do that your saying.
Yes we can by taking advantage of the struts and springs that every view has and most of the time are left to their default setting. But this time we will change them for the UIScrollView to resize itself to the size of the screen / device it ends up being run on. And change them for the content view to not resize at all, i.e. to stay big. When the app runs the scrollview will shrink down to the size of the device and the content will stay it’s actual correct size.
Here are the settings for the scrollview:
and the settings for the content view:
this leaves you with a nice big view you can design:
One last thought if your scrollview is not the full size of the screen (most times it is) then you could resize the UIScrollView in viewDidLoad to the custom size and position that you need.