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,021 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
- 739
- 9
- 21
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,256
- 34
- 50
- 104
-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,313
- 2
- 28
- 40
Jaya chandra
- 15
- 1