I have a collectionView with pagedEnable and horizontal scroll. I just want to add dot of pageControl to my collectionView when scrolling.
Asked
Active
Viewed 1,165 times
0
-
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 Answers
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

Jaya chandra
- 19
- 1