Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Dynamic Height to UIScrollView Swift

how can i set the dynamic height of UIScrollView based on the content/ subviews i have in my ScrollView

Here is what i am getting as output:

enter image description here

like image 374
Jayesh Gyanchandani Avatar asked Dec 03 '16 06:12

Jayesh Gyanchandani


1 Answers

We can use auto layout, where we use a content view in scrollview, which can be pinned to the scrollview and the height and width constraints given equal to the main view. Then if we want the height to vary dynamically we can give height constraint a low priority compared to the others and hence the content view's height will increase based on its intrinsic size, because of its sub views.

Reference Links:

1) https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithScrollViews.html#//apple_ref/doc/uid/TP40010853-CH24-SW1

2) https://www.youtube.com/watch?v=6J22gHORk2I

like image 91
Patrick R Avatar answered Nov 15 '22 20:11

Patrick R