views:

85

answers:

2

Shouldn't there be a way to resize the frame of a UIView after you've added subviews so that the frame is the size needed to enclose all the subviews? If your subviews are added dynamically how can you determine what size the frame of the container view needs to be? This doesn't work:

[myView sizeToFit];
A: 

Whatever module that dynamically added all these subviews had to know where to put them (so they relate properly, or so they don't overlap, etc.) Once you know that, plus the size of the current view, plus the size of the subview, you have all you need to determine if the enclosing view needs to be modified.

hotpaw2
true, I could set it manually or by doing a lot of math. But there is a sizeToFit method of UIView, that in the documentation says "Resizes and moves the receiver view so it just encloses its subviews." Shouldn't that do it?
sol
A: 
[myView sizeToFit];

Should work, why don't you check the CGRect before and after?

Jordan
I have the view's background color set to Red, and it does not change when I call sizeToFit, even though some of the subviews are located outside the frame.
sol
Can you post the code?
Jordan