0
I’m creating an app for iOS
using Swift
, I’m having a lot of difficulty regarding the height of UIScrollView
, I’m using auto-layout
and create the following structure:
- Uiscrollview
- Uiview // View where I insert 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 insert the components
I am currently using the following logic to calculate the height for the 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’d like to know some way to set the time for the UIScrollView
accurately.