Search code examples
iosuiscrollviewstoryboardautolayoutxcode5

How to make a ScrollView with AutoLayout in Xcode5


In xcode 5 using storyboards how would one make a fully operational vertical scrolling scrollview, with AutoLayout ON?
Considering the subviews have hierarchy:

  1.UIView  
    2.UIScrollView
      3.UIView (lets call this UIDetailView to make things easier)

Please be specific from code to constraints to wether any of the views HAS to be smaller etc.


Solution

  • This blog post details how to use a UIScrollView with Autolayout ON, using a pure autolayout approach. Note though that all constraints in the blog post are defined through the Storyboard.

    The approach in the post assumes the following hierarchy:

    1. View (main view of my UIViewController)
      2. Scroll View (UIScrollView)
         3. Container View (UIView)
           4. Content View (e.g. UIImageView)
    

    I guess the Container View will be your UIDetailView, and the Content View will be any UIView inside your UIDetailView.

    https://happyteamlabs.com/blog/ios-how-to-use-uiscrollview-with-auto-layout-pure-auto-layout/