I'm creating an application for iOS
using Swift
, I'm having a lot of difficulty regarding height of UIScrollView
, I'm using auto-layout
and I create the following structure:
- UIScrollView
- UIView // View where I enter the components
- UIImageView // Constraint Top Edges 20 in relation to UIView
- UITextView // Constraint Top Edges 40 in relation to UIImageView
- UITextView // Constraint Top Edges 20 in relation to UITextView
- UIButton // Constraint Top Edges 30 in relation to UIButton
- UIView // View where I enter the components
I'm currently using the following logic to calculate the height for UIScrollView
override func viewDidLayoutSubviews() {
var scrollHeight : CGFloat = 0.0
for view in self.containerView.subviews {
view.layoutIfNeeded()
scrollHeight += view.frame.size.height
}
// Adicionar o tamanho da scrollview, de acordo com a soma
// das alturas das views filhas
self.scrollView.contentSize.height = scrollHeight
}
But I can only get the height of the items, without calculating the spaces created by constraints
. I would like to know some way to set the height for UIScrollView
accurately.