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.
-(0,0)(320,0)(640,0)(960,0)
// 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);
No comments:
Post a Comment
Kamleshwar