I want to display the images present in my database on the Scroll view.Also i want to display 4 images in a row then next 4 in next row and so on.Initially the scroll view will show only 2 rows and after scrolling vertically the user will be able to scroll through all the images present in the database.Can anyone suggest any suitable measures to do this or provide any sample demo or code for this.Any help will be appreciated.
I am using this code to get images in horizontal fashion .How can i do it in vertical fashion after 5 images in a row.My code:-
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
CGFloat curXLoc = 40;
// reposition all image subviews in a horizontal serial fashion
//CGFloat curYLoc = 0;
for (view in subviews)
{
//if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
if(view)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 40);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((20 * kScrollObjWidth),[scrollView1 bounds].size.height)];
//[self layoutScrollLabels];
}
And in view did load i created scroll view as:-
scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(25,48,630,180)];
[scrollView1 setBackgroundColor:[UIColor lightGrayColor]];
[scrollView1 setCanCancelContentTouches:NO];
//scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
//scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
scrollView1.pagingEnabled=YES;
scrollView1.showsVerticalScrollIndicator = YES;
//scrollView1.showsHorizontalScrollIndicator = YES;
//scrollView1.alwaysBounceVertical = YES;
//scrollView1.alwaysBounceHorizontal = NO;
[self.view addSubview:scrollView1];
Thanks,
Christy
——Updated——-
—–Updated Finished——-
Here you are,
Above code was for iPad setting Images with 100 & 80 width & height respectively. . cx and cy variables are used to keep track for positioning next image. In 1 line here 6 Images are possible (Landscape mode). Modify code for the same as per your requirement.
If you need further help please leave a comment.
Hope this helps.