To create your views programatically, use viewDidLoad: of your UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
for(int i=0;i<50;i++){
//provide some initial frame, set the correct frames in viewWillLayoutSubviews:
CGRect frame = CGRectMake(0,i*10;100;5);
//create a new UIView, use your own UIView subclass here if you have one
UIView *view = [[UIView alloc] initWithFrame:frame];
//set it's backgroundColor in case you are copy&pasting this code to try it out, so you see that there are actually views added ;)
view.backgroundColor = [UIColor blueColor];
//add it to the viewController's view
[self.view addSubview:view];
//you might consider creating an NSArray to store references to the views for easier access in other parts of the code
}
}
To create a view that you designed in a storyboard use something like described here: https://stackoverflow.com/a/13390131/3659846
MyViewController *myViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MyScene"];
[self.view addSubView:myViewController.theViewToAdd];
To create a view from a nib file, use the approach described here: https://stackoverflow.com/a/11836614/3659846
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"yourNib" owner:nil options:nil];
UIView *view = [nibContents lastObject]; //assuming the nib contains only one view
[self.view addSubview:view];