Create the UIScrollView Programmatically

With the help of  the UIScrollView we will able to  display content that is larger than the size of the application’s window. It enables users to scroll the view and to see the full contents.
//Creating the scroll view
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//Create the views which are going to display in the scrollview.
int count= 4;
for (int i = 0; i
CGFloat y = i * self.view.frame.size.width;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];
view.backgroundColor = [UIColor greenColor];
[scrollview addSubview:view];
[view release];
// X will place every UIView exactly where the previous UIView ‘s frame ended.
// The x and y coordinates for creating the new 4 views will be.
// We are increasing the x coordinate to 320, We can able to add the views horizontally one after other.
// ContentSize is nothing, it is size of the total view(Total size of 4 views) Content size will be (1280,480)
// Set the UIScrollView contentSize
scrollview.contentSize = CGSizeMake(self.view.frame.size.width * count, self.view.frame.size.height);

Tags: , , , ,

This entry was posted by admin on Saturday, July 23rd, 2011 at 1:29 AM and is filed under iPhone Apps, iPhone Interview, Objective C, xCode Bascis, Programming . You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.

Comments are closed.