我需要创建一个水平的UIScrollView,它可以容纳数百个缩略图,就像缩略图一样.
例如,在单个屏幕中将显示10个缩略图,每个缩略图彼此水平相邻.
我的问题是我不知道如何制作一个水平的UIScrollView来保存同时显示的多个缩略图?
样本照片如下.请参见屏幕底部.

谢谢.
Jan*_*mal 37
您可以以编程方式将所有缩略图添加到scrollview,并使用UIScrollView的setContentSize方法.你必须在contentOffset中传递2个值.1表示宽度,1表示高度.请点击链接以了解更多相关信息.如果您需要进一步的帮助,请发表评论.
希望能帮助到你.
请考虑以下示例.
- (void)setupHorizontalScrollView
{
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = NO;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSUInteger nimages = 0;
NSInteger tot=0;
CGFloat cx = 0;
for (; ; nimages++) {
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", (nimages + 1)];
UIImage *image = [UIImage imageNamed:imageName];
if (tot==15) {
break;
}
if (4==nimages) {
nimages=0;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = 40;
rect.size.width = 40;
rect.origin.x = cx;
rect.origin.y = 0;
imageView.frame = rect;
[scrollView addSubview:imageView];
[imageView release];
cx += imageView.frame.size.width+5;
tot++;
}
self.pageControl.numberOfPages = nimages;
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43732 次 |
| 最近记录: |