What's the best way of handling a UIPageControl that has so many dots they don't all fit on the screen

I created an eBook application that used UIScrollView that contained a UIWebView. The book had over 100 pages so UIPageControl could not handle it because of the problem you pointed out. I ended up creating a custom "slider" type view that acted similar to UIPageControl but could handle the large number of pages. That's pretty much what you will need to do. UIPage control cannot handle as many pages as you want...


Calculate the pages/dot ratio and store as float value. Then calculate current dot number as current page/pagesPerDot. You may need to advance a few pages before seeing the dot move, but it's very scalable and works well.


I had to implement UIPageControl under my horizontal collection view which had 30 items. So what i did to reduce the number of dots by fixing the number of dots and scroll in those dots only. Follow the code:

@IBOutlet var pageControl: UIPageControl!
var collectionDataList = [String]
let dotsCount = 5

override func viewDidAppear(_ animated: Bool) {
    if collectionDataList.count < dotsCount {
        self.pageControl.numberOfPages = collectionDataList.count
    } else {
        self.pageControl.numberOfPages = dotsCount
    } 
}

func scrollViewDidScroll(_ scrollView: UIScrollView)
{
   let pageWidth = scrollView.frame.width
   self.currentPage = Int((scrollView.contentOffset.x + pageWidth / 2) / pageWidth)
   self.pageControl.currentPage = self.currentPage % dotsCount

}