문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top