Learning the basics of UIScrollView
Solution 1:
Here is a scroll view guide from Apple
The basic steps are:
- Create a
UIScrollView
and a content view you want to put inside (in your case aUIImageView
). - Make the content view a subview of the scroll view.
- Set the content size of the scrollview to the frame size of the content view. This is a very important step that people often omit.
- Put the scroll view in a window somewhere.
As for the paging behavior, check out UIScrollView’s pagingEnabled
property. If you need to scroll by less than a whole page you’ll need to play tricks with clipsToBounds
, sort of the reverse of what is happening in this StackOverflow question.
Solution 2:
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSInteger viewcount= 4;
for (int i = 0; i <viewcount; i++)
{
CGFloat y = i * self.view.frame.size.height;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y,self.view.frame.size.width, self .view.frame.size.height)];
view.backgroundColor = [UIColor greenColor];
[scrollview addSubview:view];
[view release];
}
scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height *viewcount);
For more information Create UIScrollView programmatically