I'm creating a application using Swift3
, and i have difficult to define correctly height for UIScrollView
, i'm using autolayout
and create this structure:
UIScrollView
UIView
// The containerview
UIImageView
//Constraint
Top Edges = 20 in relation toUIView
UITextView
//Constraint
Top Edges = 40 in relation toUIImageView
UITextView
//Constraint
Top Edges = 20 in relation toUITextView
UIButton
//Constraint
Top Edges 30 in relation toUITextView
Currently, i'm using this logic to calculate UIScrollView
height
override func viewDidLayoutSubviews() {
var scrollHeight : CGFloat = 0.0
for view in self.containerView.subviews {
view.layoutIfNeeded()
scrollHeight += view.frame.size.height
}
// Adding height for scrollview, according to the sum of all child views
self.scrollView.contentSize.height = scrollHeight
}
But, i can only get the views
height, and them not consider the Constraints
"margins", i would like know any way to calculate correct height for UIScrollView
, adjusted according their content.