0

I have a collectionView with pagedEnable and horizontal scroll. I just want to add dot of pageControl to my collectionView when scrolling.

sann chhailong
  • 53
  • 2
  • 10
  • Add a PageControl over the CollectionView and implement ScrollViewDidScroll of UIScrollViewDelegate and set current page of PageControl. – Yahya Ibrahim Mar 02 '17 at 04:21

3 Answers3

2

Set number of pages in the pageControl

NSUInteger numberOfCells = 10;
_pageControl.numberOfPages = numberOfCells;

Implement scrollView delegate method

 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
 // Suppose your collectionview cell width is equal to your screen size
 CGFloat collectionViewCellWidth = self.view.frame.size.width;     
_pageControl.currentPage = (scrollView.contentOffset.x / collectionViewCellWidth);
}
Pooja Gupta
  • 785
  • 10
  • 22
0

Implement the scroll view's delegate method as follows:-

Say collectionViewTestimonial : Name(IBOutlet) of your collection view, pageControlTestimonial: Name of page control

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat pageWidth = collectionViewTestimonial.frame.size.width;
    pageControlTestimonial.currentPage = collectionViewTestimonial.contentOffset.x / pageWidth;
}
pkc456
  • 8,350
  • 38
  • 53
  • 109
-1

Try like this :

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
 // Suppose your collectionview cell width is equal to your screen size
 CGFloat collectionViewCellWidth = self.view.frame.size.width;     
_pageControl.currentPage = (scrollView.contentOffset.x / collectionViewCellWidth);
}
Himanth
  • 2,381
  • 3
  • 28
  • 41