-ViewController
--View
---ScrollView
----View
-----TextView
-----Label
-----etc
I am trying to set contentSize of UIScrollView by following.
let lastView : UIView! = scrollView.subviews.last
let height = lastView.frame.size.height
let pos = lastView.frame.origin.y
let sizeOfContent = height + pos
scrollView.contentSize.height = sizeOfContent
But, it's not working. Any suggestions ?
first of all, you have to provide scrollview constraints like top to superview, leading to superview, bottom to superview, trailing to superview.
Then provide scrollview's subview known as view constraint like leading, trailing, bottom and top constraint to scrollview.
And then provide scrollview's subview known as view constraint like equal width and equal height to the main view.
And change the lastly provided constraint equal height priority to 251.
This should make scrollview dynamically change accroding to the content.
Try it!!!