我已经搜索并搜索了这个教程,但没有一个是我正在寻找的。我试过苹果的样品,但它只是颜色,我不知道如何使它的意见。我正在寻找的是一个显示页面控制的页面。每次滚动视图页面我都希望它显示与按钮完全不同的视图,很像iPhone的主屏幕。我发现下面的示例代码仅适用于图片,但我想修改为使用单独的视图。请帮忙!谢谢。如何结合UIScrollview和UIPagecontrol显示不同的视图?
- (void)setupPage {
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor clearColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSUInteger nimages = 0;
CGFloat cx = 0;
for (; ; nimages++) {
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", (nimages + 1)];
UIImage *image = [UIImage imageNamed:imageName];
if (image == nil) {
break;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = image.size.height;
rect.size.width = image.size.width;
rect.origin.x = ((scrollView.frame.size.width - image.size.width)/2) + cx;
rect.origin.y = ((scrollView.frame.size.height - image.size.height)/2);
imageView.frame = rect;
[scrollView addSubview:imageView];
[imageView release];
cx += scrollView.frame.size.width;
}
self.pageControl.numberOfPages = nimages;
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
我不确定为什么你需要分页控制,因为scrollview有一个内置的。如果你想在scrollview中做一个pagecontrol,那么你需要添加一个新的pageview,就像你用imageview – Burf2000 2010-12-09 23:57:37
@ Burf2000:从什么时候'UIScrollView`出现'UIPageControl`? – BoltClock 2010-12-10 03:28:33