Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

arnieterm

macrumors regular
Original poster
Aug 28, 2008
201
0
After much reading through the documentation, I am clueless in a design related issue. My problem is as given below:
There is one main UIView viewMain that has three UIView in it
1. viewheader
2. viewDetails
3. ViewBottom
My application requires that sometimes based on contents of the viewHeader and viewDetails may increase more space than given in design time like some labels may go in more than two lines etc
Is it possible at design time that when the subviews in viewHeader and viewDetails resizes these two views also resizes so that viewDetails move some space down so as to make room for viewHeader. Same is expected for viewBottom
It seems to me that I am still not able to understand the autoresizing behaviour of views and their containers
Thanks
Arnieterm
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Autoresizing works in relation to changes to the superview and not sibling views. I suspect what you'll need to do is programatically adjust the frames of these views in relation to the changes in the other views.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Various comments:

Typically views automatically resize when a) their superview resizes (automatically or not), b) after autorotation, and c) when a view controller is pushed. Other than that if you want to resize a particular view you need to have code somewhere that causes it to resize. That would usually be in its view controller or in its superview. layoutSubviews is common place for this kind of code to take advantage of the existing infrastructure to layout views.

Obviously the autoresizing behaviour is based on the autoresizeMask property. Not so obviously, autoresizing behavior is based on a superview-subview relationship. Peer views aren't involved in autoresizing. So if a superview is resized in code or because of a rotation it will resize its subviews. But it's not possible to directly express the relationship of two peer views to each other. You can only express the relationship of two peer views to their container view. If there needs to be a relationship beetween peer views it needs to be implemented in their containerView or view controller.

In your example I don't think there's an automatic way for a superview to resize based on its contents. You can't make viewDetails automatically get bigger because its subviews get bigger. You can however implement layoutSubviews in viewDetails to do this. You would then update the contents of the subviews and then send setNeedsLayout to viewDetails. For labels you can use sizeToFit to have them adjust their sizes to their contents. In the viewDetails layoutSubviews it would check the sizes of its subviews and then position them according to your design.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.