iOS_iOS14.0 adaptation

iOS14.0 adaptation, record!

adaptationUIPageControl

  • Problem:
    iOS14After deleting pageImageand currentPageImage, you can no longer KVCmodify the picture of the controller.
  • Solution:
    With the help of the iOS14new field preferredIndicatorImage, we can modify the size and shape of the indicator dot, and use currentPageIndicatorTintColorand pageIndicatorTintColorto confirm the color of the dot in different states.
    The color of the final display is determined by TintColorand preferredIndicatorImagejointly, so here will be preferredIndicatorImageset to white.
  • Some code examples::
UIPageControl *pageControl = [[UIPageControl alloc]init];
pageControl.backgroundColor = [UIColor clearColor];
pageControl.numberOfPages = 1;
if (@available(iOS 14.0,*)) {
   pageControl.preferredIndicatorImage = [self imageWithColor:[UIColor whiteColor]];
   pageControl.currentPageIndicatorTintColor = [UIColor redColor];
   pageControl.pageIndicatorTintColor = [UIColor blueColor];
}else{
   [pageControl setValue:[UIImage imageNamed:@"pageControllDot"]forKeyPath:@"pageImage"];
   [pageControl setValue:[UIImage imageNamed:@"pageControllCurrent"]forKeyPath:@"currentPageImage"];
 }
// 绘制小圆点的形状
- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 12.f, 2.f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

Guess you like

Origin blog.csdn.net/FlyingKuiKui/article/details/108711014