iOS 14 UIPageControl未选中的页面被视为currentPage
iOS 14 UIPageControl unselected page are treated as currentPage
当我使用 setIndicatorImage 为 UIPageControl 设置图像时,未选中页面的色调颜色设置为 currentPageIndicatorTintColor,但当前页面的色调颜色是默认指示器色调颜色。
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
}
最后我通过在设置指示器图像循环后调用设置当前页面解决了这个问题。代码片段如下所示。
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;
当我使用 setIndicatorImage 为 UIPageControl 设置图像时,未选中页面的色调颜色设置为 currentPageIndicatorTintColor,但当前页面的色调颜色是默认指示器色调颜色。
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
}
最后我通过在设置指示器图像循环后调用设置当前页面解决了这个问题。代码片段如下所示。
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;