When I use setIndicatorImage to set image for the UIPageControl, unselected page's tint color are set to the currentPageIndicatorTintColor, but current page's tint color is default indicator tint color.
self.customPageControl.currentPage = currentPage;
if (@available(iOS 14.0, *)) {
_pageControl.pageIndicatorTintColor = [UIColor blueColor];
_pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
for(int i=0; i<self.pageControl.numberOfPages; i++){
if(i == currentPage){
[self.pageControl setIndicatorImage:[UIImage imageNamed:@"pageCtrlSelected"] forPage:i];
}
else{
[self.pageControl setIndicatorImage:[UIImage imageNamed:@"pageCtrlUnselect"] forPage:i];
}
}
} else {
// Fallback on earlier versions
}
Finally I solved this by call set current page after set indicator image loop. The code snipper is like below.
if (@available(iOS 14.0, *)) {
_pageControl.pageIndicatorTintColor = [UIColor blueColor];
_pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
for(int i=0; i<self.pageControl.numberOfPages; i++){
if(i == currentPage){
[self.pageControl setIndicatorImage:[UIImage imageNamed:@"pageCtrlSelected"] forPage:i];
}
else{
[self.pageControl setIndicatorImage:[UIImage imageNamed:@"pageCtrlUnselect"] forPage:i];
}
}
} else {
// Fallback on earlier versions
}
/// It's important that set currentPage after set indicator image !!!!
self.customPageControl.currentPage = currentPage;