views:

363

answers:

2

I've been looking at the way resiznig works in Cocoa Touch and it looks like without writing any code, a UIView cannot be set up to size itself based on the size of it's children. There are plenty of options to resize and re-position child views when their containing view changes size, but nothing that works the other way round as far as I can tell.

I wanted to check that this is the case before I do a load of subclassing to override sizeThatFits:

+1  A: 

Im pretty sure you can use the method sizeToFit. It will resize the UIView based on its children's views, but you need to make sure that the children are also fit properly.

gburgoon
I know you can write code to size a view using sizeToFit to measure the desired size of child views. I was asking if there's a built in way to do it, i.e. by just setting properties (either in Interface Builder or in code).
U62
sizeToFit automatically resizes a given view. so calling that on a UIView will resize it to the dimensions of the children. No extra code required. The only problem is if your children are sized properly.
gburgoon
+1  A: 

The answer is that there isn't a property you can set on a view to have to automatically resize when it's children resize. No doubt you could code something up that did it and there are 3rd party layout frameworks for both Cocoa and CocoaTouch that overcome it's many shortcomings. But there's nothing built in.

U62