开发者

using UIScrollView generating issues

This 开发者_如何学JAVAmay be a simple problem. I have a UIScrollView with 3 views. I need to display 3 dots like Indicator ( to indicate there are more pages to the user). How do i do this?


use a UIPageControl:

pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(...)]; // set in header
[pageControl setNumberOfPages:3];
[pageControl setCurrentPage:0];
[pageControl setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:pageControl];

That is the UI component that shows the dots... the number of pages is the number of dots. The current page is the one that is currently highlighted.

Then you need to use the scroll view delegate method to determine what page you've scrolled to:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  int newOffset = scrollView.contentOffset.x;
  int newPage = (int)(newOffset/(scrollView.frame.size.width));
  [pageControl setCurrentPage:newPage];
}


You could create contentView in which you add UIScrollView and UIPageControl, set numberOfPages of pageControl to selected count and when you scroll you change page in your pageControl ( currentPage property ).

Cheers, Krzysztof Zabłocki


You can use a UIPageControl with 3 dots on it. You'll need screen space (assuming the bottom of the screen) to put the page control so your scrollview won't be able to be full height.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜