How To Use UIScrollView To View Without Using Interafce Builder In iPhone

In this application we will see how to use UIScrollView to View an image larger than the screen without using Interface Builder. So we have to write some code for the  ScrollView. Basically this tutorial will show you the basics of using the UIScrollView when programming for the iPhone.

Step 1: Create aView base application using template. Give the application name “ScrollImage”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3:We need to add the resource file called as “cartoon.jpg” into the resource folder. Select resources and add files existing sources and select the cartoon.jpg.

Step 4: Open the ScrollImageViewController.m file make the following changes in the file.

 

- (void)viewDidLoad {
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(847, 800);
UIImage *image = [UIImage imageNamed:@"cartoon.jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
[image release];
[scrollView addSubview:imageView];
[imageView release];
[self.view addSubview:scrollView];
[scrollView release];

}

 

 

Step 5: Now compile and run the application in the simulator.

You can downloaded SourceCode from here ScrollImage 2

Leave a Comment: