My page control UI is not getting updated. The page control number is getting updated every time, but it's not being updated in the Page Control UI. I thought maybe using updateCurrentPageDisplay would work, or that was what I was missing, but I just received an error. Here is my code. Am I missing something that's need to update the UI?
@IBOutlet weak var pageControl: UIPageControl!
override func viewDidLoad() {
super.viewDidLoad()
collection.delegate = self
collection.dataSource = self
thisWidth = CGFloat(collection.frame.width)
pageControl.hidesForSinglePage = true
pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray
pageControl.currentPageIndicatorTintColor = UIColor.red
pageControl.numberOfPages = 10
pageControl.currentPage = 0
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CalanderCollectionViewCell
let imagePath = array[indexPath.section]
cell.configureCell(properties: imagePath)
return cell
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
self.pageControl.currentPage = indexPath.section
print("current page\(pageControl.currentPage)")
pageControl.updateCurrentPageDisplay()
print(indexPath.section)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
thisWidth = CGFloat(collection.frame.width)
return CGSize(width: thisWidth, height: collection.frame.height)
}
Delete this line:
pageControl = UIPageControl.appearance()