Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using UIScrollView generating issues

This may 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?

like image 241
Charith Nidarsha Avatar asked Oct 07 '10 15:10

Charith Nidarsha


1 Answers

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];
}
like image 168
Thomas Clayson Avatar answered Sep 28 '22 15:09

Thomas Clayson