I have a scrollview inside which i have 20 UItextviews. The scrollview is not working. I have set the following in viewdidload.
self.MainScroll.contentSize = CGSizeMake(320, 1800);
Still it doesn't scroll. However, if i give bounce vertically, it just bounces. My scrollview is a child of the main UIview of dimension 320*600. Please guide how to enable the scroll!!
There are two ways you can get the scrolling to work.
Approach 1 (with code):
1) Pin
UIScrollView
to the sides of its parent view, as mentioned below.2) Set content size of your scroll view in
viewDidLayoutSubviews
:Approach 2 (pure IB, no code required):
1) Setting
contentSize
is not required if usingAutoLayout
. You need to pin yourUIScrollView
to the parent view as mentioned below:2) Then add another
UIView
inside UIScrollView to act as a content view and pin it to the UIScrollView and move all controls inside this content view:3) Pin content view to its parent scroll view as mentioned below:
4) Set your UIViewController's Simulated Metrics to Freeform (this is important):
5) Size your content
UIView
to your desired height (obviously important too):Update the content size after some delay as below.