データベースに存在する画像をスクロールビューに表示したい。また、4つの画像を続けて表示し、次の4つを次の行に表示したい、というように続けます。最初はスクロールビューに2行しか表示されず、ユーザーを垂直にスクロールした後データベースに存在するすべての画像をスクロールできるようになります。これを行うための適切な手段を提案したり、このためのサンプルデモやコードを提供したりできます。
私はこのコードを使用して、水平方向の画像を取得しています。5つの画像を続けて取得した後、垂直方向に取得するにはどうすればよいですか。私のコード:-
- (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];
}
そして、ビューでロードしました:私はスクロールビューを次のように作成しました:-
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];
ありがとう、クリスティ