views:

81

answers:

1

Guys, I am a newbee for iOS. I need to create dynamic layout since the GUI will be generated according to the data. I checked the UIView references, it seems the standard way to add subview is like:

CGRect rect = CGRectMake(0, 0, width, height);
UILabel *label = [[UILabel alloc] initWithFrame: rect];
[someView addSubView: label];

But, maybe I can't be sure that the width and the height. In Java, container use layout manager to automatically deal with the width and height based on some rules. In iOS, can I use something like layout manager in Java?

Thanks. Any clue will be OK.

+1  A: 

You can do this in iOS, although it is not one-to-one with Java layouts. The get the idea of what is possible, use the Size Inspector in Interface Builder. Anything that is done there, such as allowing an item to grow horizontally or stay the same distance from the top, can be done programmatically. If further customization is needed, you can override event hooks in your view or controller, such as UIView's -layoutSubviews method.

Peter DeWeese
Thanks Peter, I will check out what I can do in -layoutSubviews.
icespace