I have a UIPageControl in my application that looks perfectly fine with around 10 pages (dots), it\'s possible however for the user to add many different views, and so the numbe
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
}