我想在滚动视图上显示我的数据库中存在的图像。此外,我想在一行中显示 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];
谢谢,克里斯蒂