Created my tutorial here and you can download the source code too.
I will add more to this tutorial as I have time such as how to add views and additional properties for the UIScrollView and such. I say download the source code for the commented directions and details.
How to create a UIScrollView and set it’s size and content.
1. Create an iPhone app with Xcode using View-based Application and name it ScrollViewTutorial.
2. Open up ScrollViewTutorialViewController.h and add these two lins:
UIScrollView *myScrollView;
@property (nonatomic, retain) IBOutlet UIScrollView *myScrollView;
The final ScrollViewTutorialViewController.h file should look like this:
#import <UIKit/UIKit.h>
@interface ScrollViewTutorialViewController : UIViewController {
UIScrollView *myScrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *myScrollView;
@end
3. Now lets add open up ScrollViewTutorialViewController.m and add these lines:
@synthesize myScrollView;
myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(960, 480);
myScrollView.pagingEnabled = TRUE;
myScrollView.scrollEnabled = FALSE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];
[myScrollView release];
The final ScrollViewTutorialViewController.m file should look like this:
#import “ ScrollViewTutorialViewController.h”
@implementation ScrollViewTutorialViewController
@synthesize myScrollView; // don’t forget to synthesize your UIViewController
- (void)viewDidLoad {
myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(960, 480);
myScrollView.pagingEnabled = FALSE;
myScrollView.scrollEnabled = TRUE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];
}
- (void)dealloc {
[myScrollView release];
[super dealloc];
}
@end
There you go. Creating a UIScrollView with size of the iPhone screen and *content* size of 3 pages.