1

How to create a view hierarchy programmatically without using a nib ?

Brian Webster
  • 28,703
  • 48
  • 145
  • 221
Ferdinand
  • 1,175
  • 4
  • 22
  • 43

1 Answers1

3

The whole view hierarchy can be constructed using successive UIView construction and -addSubview: methods.

For instance, to create an input form one may use

UIView* rootView = [[UIView alloc] initWithFrame:...];
// apply style to rootView
[window addSubview:rootView];
[rootView release];

UILabel* inputLabel = [[UILabel alloc] initWithFrame:...];
// apply style to label
[rootView addSubview:inputLabel];
[inputLabel release];

UITextField* inputField = [[UITextField alloc] initWithFrame:...];
// apply style to text field
[rootView addSubview:textField];
[textField release];

and so on.

kennytm
  • 491,404
  • 99
  • 1,053
  • 989