I have the following code to create a view and put it in scrollview to allow paging
the code works fine however what I couldn’t do is loading views from a nib file
in other words
I want to use “initWithNibName” instead of “initWithFrame”?
- (void)createPageWithColor:(UIColor *)color forPage:(int)page
{
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 300,400)];
newView.backgroundColor = color;
[scrollView addSubview:newView];
}
Thanks alot
I think the thing you’re missing is that you can set the frame of your new UIView after loading the nib. Load/Init time isn’t your only shot at that. I’m also breaking the load function into its pieces, in the code below, so you can see more easily what’s going on.
Observe:
Don’t forget that for that UIScrollView to actually scroll, you need to set its contentSize property to the size of the goods inside it, which is likely bigger than the .frame property of the scroll view itself.