Question

The problem I am forcing is: I have 1 big scrollView and I have to add to it 5 subviews programmatically when I don't know what heights the sub views will have :(

Is there some API to do so ? or I have to count the subviews heights manually and add them with CGRectMake based by calculated sizes?

Was it helpful?

Solution

What I would do is use Auto Layout. If you add your subviews to the scroll view using internal constraints, then these constraints can determine not only the distance of the subviews from one another but also the distance from the imaginary content view that surrounds them. The scroll view then uses the size of the content view as its contentSize, and the whole thing becomes scrollable. And this works despite the fact that you don't know the heights of any of the views, which is exactly what you're after.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top