这可能是一个简单的问题。我有一个具有 3 个 View 的 UIScrollView。我需要显示 3 个点,如 Indicator(以指示用户有更多页面)。我该怎么做?
最佳答案
使用 UIPageControl:
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(...)]; // set in header
[pageControl setNumberOfPages:3];
[pageControl setCurrentPage:0];
[pageControl setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:pageControl];
那是显示圆点的 UI 组件……页数就是圆点数。当前页面是当前突出显示的页面。
然后您需要使用 ScrollView 委托(delegate)方法来确定您滚动到的页面:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
int newOffset = scrollView.contentOffset.x;
int newPage = (int)(newOffset/(scrollView.frame.size.width));
[pageControl setCurrentPage:newPage];
}
关于iphone - 使用 UIScrollView 生成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3883296/