贝塞尔曲线

本文详细介绍了两种使用Core Graphics在iOS应用中绘制圆环进度条的方法,包括贝塞尔路径和CAShapeLayer的使用,展示了如何实现动态变化的进度显示效果。

第一种加载方法

- (void)drawRect:(CGRect)rect {
    UIBezierPath *backPath = [UIBezierPath bezierPath];
    [backPath moveToPoint:CGPointMake(0, 0)];
    [backPath addLineToPoint:CGPointMake(0, rect.size.height)];
    [backPath addLineToPoint:CGPointMake(rect.size.width, rect.size.height)];
    [backPath addLineToPoint:CGPointMake(rect.size.width, 0)];
    [backPath closePath];
    [self.superview.backgroundColor set];
    [backPath fill];
    
    
    CGFloat width = MIN(CGRectGetWidth(rect), CGRectGetHeight(rect));
    CGFloat lineW = 3 / [UIScreen mainScreen].scale;
    
    UIBezierPath *backProPath = [UIBezierPath bezierPath];
    [backProPath addArcWithCenter:CGPointMake(width / 2., width / 2.) radius:width / 2. - 10 startAngle:0 endAngle:M_PI * 2 clockwise:true];
    backProPath.lineWidth = lineW;
    [[UIColor grayColor] set];
    [backProPath stroke];
    
    
    UIBezierPath *progressPath = [UIBezierPath bezierPath];
    [progressPath addArcWithCenter:CGPointMake(width / 2., width / 2.) radius:width / 2. - 10 startAngle:0 endAngle:M_PI_4 clockwise:true];
    progressPath.lineWidth = lineW;
    [[UIColor redColor] set];
    [progressPath stroke];
}

 

第二种加载方法

- (void)drawRect:(CGRect)rect {
    UIBezierPath *tempPath = [UIBezierPath bezierPathWithRect:rect];
    [self.superview.backgroundColor set];
    [tempPath fill];
    
    
    CGFloat width = MIN(CGRectGetWidth(rect), CGRectGetHeight(rect));
    
    
    CAShapeLayer *backLayer = [CAShapeLayer layer];
    
    backLayer.lineWidth = 3 / [UIScreen mainScreen].scale;
    backLayer.strokeColor = [UIColor cyanColor].CGColor;
    backLayer.fillColor = [UIColor redColor].CGColor;
    
    [self.layer addSublayer:backLayer];
    
    UIBezierPath *backPath = [UIBezierPath bezierPath];
    [backPath addArcWithCenter:CGPointMake(width / 2., width / 2.) radius:width / 2. - 3 startAngle:0 endAngle:M_PI_4 clockwise:true];
    
    
    backLayer.path = backPath.CGPath;
}

 

转载于:https://www.cnblogs.com/shenhongbang/p/4776667.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值