Here is an example of how you can do this:
- (void)viewDidLoad
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:scrollView];
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(320*2, 460);
controllers = [[NSMutableArray alloc] initWithCapacity:0];
LabeledViewController *one = [[LabeledViewController alloc] initWithPosition:0 text:@"one"];
[scrollView addSubview:one.view];
[controllers addObject:one];
LabeledViewController *two = [[LabeledViewController alloc] initWithPosition:1 text:@"two"];
[scrollView addSubview:two.view];
[controllers addObject:two];
}
LabeledViewController is pretty simple, but you can add as many as you want:
@implementation LabeledViewController
- (id)initWithPosition:(NSInteger)position text:(NSString*)text
{
if (self = [super init]) {
myPosition = position;
myText = [text retain];
}
return self;
}
- (void)viewDidLoad
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(320*myPosition, 0, 320, 460)];
self.view = view;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 320, 50)];
label.text = myText;
[self.view addSubview:label];
}
source
share