UIPageControl 样式设置 兼容 iOS14
- (void)setPageControlImage {
// UIPageIndicatorView
self.pageControl.currentPageIndicatorTintColor = RGBACOLOR(0,0,0,0.0);
self.pageControl.pageIndicatorTintColor = RGBACOLOR(0,0,0,0.0);
if(@available(iOS14.0, *)) {
UIView*fview1 =_pageControl;
UIView*subView1 = fview1.subviews.firstObject;
fview1 = subView1;
subView1 = fview1.subviews.firstObject;
fview1 = subView1;
subView1 = fview1.subviews.firstObject;
if(subView1 && [subView1isKindOfClass:[UIImageViewclass]]) {
[self modfinPageControlSubViews:fview1];
}
}else{
UIImage *inactiveImage = [UIImage imageNamed:@"online_image_loading_image_dot_2"];
UIImage *activeImage = [UIImage imageNamed:@"online_image_loading_image_dot_1"];
[self.pageControl setValue:inactiveImage forKeyPath:@"pageImage"];
[self.pageControl setValue:activeImage forKeyPath:@"currentPageImage"];
}
}
- (void)modfinPageControlSubViews:(UIView *)fView {
UIImage *inactiveImage = [UIImage imageNamed:@"learning_index_page_control_image_normal"];
UIImage *activeImage = [UIImage imageNamed:@"learning_index_page_control_image_current"];
for(inti =0; i < [fView.subviewscount]; i++) {
UIImageView *dot = [fView.subviews objectAtIndex:i];
[dot.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
dot.backgroundColor = [UIColor clearColor];
if (i == _pageControl.currentPage) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, activeImage.size.width, activeImage.size.height)];
imageView.image= activeImage;
[dotaddSubview:imageView];
}else{
UIImageView*imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, inactiveImage.size.width, inactiveImage.size.height)];
imageView.image= inactiveImage;
[dotaddSubview:imageView];
}
}
}