iOS中的水平UIScrollView和数百个缩略图? [英] Horizontal UIScrollView and hundreds of thumbnail images in iOS?
问题描述
我需要创建一个水平的UIScrollView,它可以容纳数百个缩略图,就像缩略图一样。
I need to create a horizontal UIScrollView which to hold hundreds of thumbnail images, just like a slide of thumbnails.
例如,在一个屏幕上会显示10个缩略图,每个缩略图彼此水平相邻。
For example, there will be 10 thumbnails showing in a single screen, each of them are horizontally adjacent to each other.
我的问题是我不知道如何制作一个水平UIScrollView来保存同时显示的多个缩略图?
My problem is that I don't know how to make a horizontal UIScrollView to hold the multiple thumbnails which showing at the same time ?
示例照片是如下。请参阅屏幕底部。
A sample photo is as below. See the bottom part of the screen.
谢谢。
推荐答案
你可以添加全部以编程方式缩略图到您的scrollview并使用UIScrollView的setContentSize方法。你必须在contentOffset中传递2个值。 1表示宽度,1表示高度。请按照链接进行详细了解。如果您需要进一步的帮助,请发表评论。
You can add all the thumbnails programatically to your scrollview and use the setContentSize method of UIScrollView. you have to pass 2 values in contentOffset. 1 for width and 1 for height. Please follow link to explore more on this. If you need further help please leave a comment.
希望有所帮助。
请考虑以下示例。
- (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)];
}
这篇关于iOS中的水平UIScrollView和数百个缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!