Dynamic ScrollView in Xcode 12
In this post i will explain how to implement a dynamic scrollview using storyboard.
- Create new Xcode project.
- Head over to the storyboard.
- In the object library , search for “ UIScrollview”. Place it inside the ViewController.Set scroll view constraint (top, bottom, leading and trailing) as (0,0,0,0).
uncheck / Disable the content layout guides in the size inspector tab.
4. Search for “UIView” in the library , place it inside the scrollview. Set constraint (top, bottom, leading and trailing) as (0,0,0,0).For better understanding, name this view as containerView.
5. Set Container view width = scrollview width and container view height = mainview height . set height priority to 250.Please ensure that the multiplier property is set to one for height and width both .
6. Place a UIView inside container view and give (Top , leading and trailing ) (0,0,0)and height constraint .
now, the important point to keep in mind is you need to provide the bottom constraint of last view for the scrollview to work properly.
so place as many uiviews as you like ,provide constaints and give bottom constraint to the last view w.r.t the container view and you are good to go!
If you have any doubts , i have attached the video of this project below.