views:

31

answers:

3

Hi all,

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?

Thanks

+2  A: 

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];
}
Thomas Clayson
Thanks. currently I have this. But I need the 'dot like indicator'. Like in iphone main display. ( to indicate there are more apps in the horizontal direction)
charith
You don't have that at all... a UIPageControl IS the three dots. If you had this then you wouldn't have a problem.
Thomas Clayson
Thanks Thomas. Seems this is correct. I will try and let u know.
charith
Thanks. It worked
charith
A: 

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.

Ben
as long as the page control is NOT a subview of the UIScrollView there is no reason why it can't go over the scrollview at all. plus this answer doesn't give any help whatsoever except to name the class to use to display a page control.
Thomas Clayson
Yes but I was assuming you didn't want the UIPageControl (the 3 dots) showing up over your views. Its general custom to put it below the UISCrollView as representation to the user of number of pages available and current page, which is what you seem to want. Here is a good example: http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html
Ben
A: 

Hi, 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

Krzysztof Zabłocki