I would like to check a few points in this func :
func customPageControl(dotFillColor:UIColor, dotBorderColor:UIColor, dotBorderWidth:CGFloat) {
for (pageIndex, dotView) in self.subviews.enumerated() {
if self.currentPage == pageIndex {
dotView.backgroundColor = dotFillColor
dotView.layer.cornerRadius = dotView.frame.size.height / 2
}else{
dotView.backgroundColor = .white
dotView.layer.cornerRadius = dotView.frame.size.height / 2
dotView.layer.borderColor = dotBorderColor.cgColor
dotView.layer.borderWidth = dotBorderWidth
}
}
}
You do not reset colors when it's not the current page. Why ?
you set corner radius in all cases, that could be outside the if.
More critical, pageControl has only one subview (each dot is not a subview).
So what do you expect with:
for (pageIndex, dotView) in self.subviews.enumerated() { }
I would try the following:
func customPageControl(dotFillColor:UIColor, dotBorderColor:UIColor, dotBorderWidth:CGFloat) {
for (pageIndex, dotView) in self.subviews.enumerated() {
print("pageIndex", pageIndex) // You should get only 0
dotView.layer.cornerRadius = dotView.frame.size.height / 2
dotView.layer.borderWidth = dotBorderWidth
if self.currentPage == pageIndex {
dotView.backgroundColor = dotFillColor.cgColor // in case you need cgColor
dotView.layer.borderColor = // any color you need
} else {
dotView.backgroundColor = .white
dotView.layer.borderColor = dotBorderColor.cgColor
}
}
}
To get what you want, you may need to create your custom pageControl or use those 2 func:
The first would be the filled dot, the other the empty dot.
var preferredIndicatorImage: UIImage?
The preferred image for indicators.
func setIndicatorImage(UIImage?, forPage: Int)
Sets the indicator image for the specified page.