views:

53

answers:

1

A UIView has a SizeToFit method that will make the UIView fit all of it's subviews. Is there anything like that, which will just return the size that it calculates and not modify any view's frame.

I have several subviews on a UIScrollView and I want to do SizeToFit on the scroll view's contentSize, rather than it's frame. I have to do it on the contentSize, because I don't want to increase the "real" size of the UIScrollView, and the content is loaded dynamically and asynchronously so I can't do it manually when I add the subviews to the UIScrollView.

A: 

Put a UIView into the UIScrollView that has the same width and height and add all subviews to IT rather than the scrollview. Then set the clipToBounds property on the scrollview to TRUE, and call sizeToFit on your UIView. You can also set the opacity of the UIView's background to 0 making it invisible, but still showing its subviews.

thgc
I just realised that it should be the other way around: The enclosing view should be the UIView, while the inner (larger) view should be the transparent UIScrollView. Then it should work.
thgc
Are you sure, what you wrote in your answer makes sense, i had though of what you said there, but it seems a bit "unproper"
Jonathan