美文网首页
UIPageControl 样式设置 兼容 iOS14

UIPageControl 样式设置 兼容 iOS14

作者: woo_5857 | 来源:发表于2020-09-18 16:56 被阅读0次

    - (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];

            }

       }

    }

    相关文章

      网友评论

          本文标题:UIPageControl 样式设置 兼容 iOS14

          本文链接:https://www.haomeiwen.com/subject/wdzeyktx.html