- set your scroll view's
pagingEnabled
property to YES
- make your scroll view's
contentSize
property X * width
wide if you want horizontal paging or `X * height' tall if you want vertical paging.
- add subview to each "page" by adding them with the right offset for each page (`X * width' or 'X * height' depending on horizontal/vertical).ž
X is a number of pages, starting with 0.
Here is a sample with 5 horizontal pages.
int numberOfPages = 5;
UIScrollView *someScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
someScrollView.pagingEnabled = YES;
someScrollView.contentSize = CGSizeMake(numberOfPages * someScrollView.frame.size.width, someScrollView.frame.size.height);
[self.view addSubview:someScrollView];
[someScrollView release];
for (int i = 0; i < numberOfPages; i++) {
UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * someScrollView.frame.size.width + 20,
20,
someScrollView.frame.size.width - 40,
20)];
tmpLabel.textAlignment = UITextAlignmentCenter;
tmpLabel.text = [NSString stringWithFormat:@"This is page %d", i];
[someScrollView addSubview:tmpLabel];
[tmpLabel release];
}