I face with a problem about UIPageControl dots. For instance, I made a banner with scrollview and I would like to travel in banner items by clicking dots of page control added below banner scroll view, but I couldn’t find any proper option to go to the specific item by touching related page control dot.
Ex. There are 5 banner items and naturally 5 page control dots. Initially it stars from beginning and continues to the right one after another, how can I directly go to the 3. item by clicking 3. dot?
My banner and pagecontrol dots
This is my code for changing banner item with scrolling in scroll view:
pageControl.addTarget(self, action: #selector(pageControlTapped(sender:)), for: .touchUpInside)
@objc func pageControlTapped(sender: UIPageControl) {
let nextPage = self.pageControl.currentPage + 1
let newPage = nextPage < self.pageControl.numberOfPages ? nextPage : 0
let indexPath = IndexPath(row: newPage, section: 0)
self.collectionView.scrollToItem(at: indexPath, at: .left, animated: true)
}