If you’re using iOS auto layout (you should) and you’ve ever tried to add a scroll view in Interface Builder or the Xamarin iOS Designer you might have noticed that it is not an easy task. If you’re interested, here are some instructions. This is especially true if you only realize that you need a scroll view after designing your view (after you’ve realized that the keyboard covers up parts of the view).
Here’s code to inject a UIScrollView
at runtime to solve all your worries. Add this code to your base UIViewController
for all controllers that should be vertically scrollable.
In Interface Builder or Xamarin iOS Designer you’ll need to make sure you’ve not only defined constraints for the vertical position of your elements but also a constraint to define the distance from the bottom of the bottom element to the bottom of the your view controller’s view. That way, you’ll have defined the vertical size of the scroll view’s content view.
3 replies on “Making your iOS views scrollable”
[…] Making your iOS views scrollable Kerry W. Lothrop gets around a designer issue with an injection. […]
Hi there
Have a basic form using the Generic View Storyboard in Studio 2015. Have set all constraints on each control and the vertical functionality works fine. But the fields do not autosize horizontally and disappear off the edge.
Any ideas?
How exactly did you set “all constraints”? Can you give me an example for one control?