Reputation: 6777
What I have in my app is a scroll view, and a series of pictures I want the user to swipe thru that are in the scroll view. I want all of them to be visible, but still have the pages be the width of one of the pictures. How can I do this? (Tell me if I need more detail)
Upvotes: 0
Views: 161
Reputation: 3034
You need to setup your UIScrollView frame to be the size of the pictures, then set the contentSize of the UIScrollView to be the width of the number of images * image width. If you want each photo to "page" like in most apps, you would also need to set pagingEnabled to YES. You also probably want to suppress the scroll indicators.
For example:
NSArray someArrayOfUIImageViews...
NSUInteger imageWidth = 100;
pageScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,imageWidth,160)];
pageScroller.scrollEnabled = YES;
pageScroller.showsHorizontalScrollIndicator = NO;
pageScroller.showsVerticalScrollIndicator = NO;
pageScroller.pagingEnabled = YES;
pageScroller.contentSize = imageWidth * [someArrayOfUIImageViews count];
Then add the pageScroller to the parent view, then add each of the images to the pageScroller spreading them across the contentSize area...
for (UIImageView * someImageView in someArrayOfUIImageViews)
{
CGFrame frame = someImageView.frame;
frame.origin.x += frame.size.width;
someImageView.frame = frame;
[pageScroller addSubview:someImageView];
}
Upvotes: 1
Reputation: 1566
To further @max's answer, you also will most likely want to set your scroll view's clipsToBounds property to NO.
Upvotes: 0
Reputation: 16719
If I understood you correctly, you have to set the contentSize property to be as big, to fit all the images. And you have to set pagingEnabled = YES
So the frame size of your scroll would be equal to the size of the image, and content size would be the bounding rect for all the images frames.
Upvotes: 1