美文网首页
贝塞尔曲线

贝塞尔曲线

作者: 九天环佩 | 来源:发表于2016-07-15 21:23 被阅读26次

    第一种加载方法

    - (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.haomeiwen.com/subject/bvnyjttx.html