画圆

self.circleVictor.backgroundColor = [UIColor greenColor];
CAShapeLayer *circle = [self LayerWithCircleCenter:CGPointMake(self.circleVictor.center.x, self.circleVictor.center.y)
                                                          radius:self.circleVictor.width/2
                                                      startAngle:radians(0)
                                                        endAngle:radians(360)
                                                       clockwise:YES
                                                 fillColor:UICOLOR_ARGB(0xffe0e0e0)
                                                 lineDashPattern:nil];
circle.strokeColor = [UIColor redColor].CGColor;
[self.circleVictor.layer addSublayer:circle];

// circle.strokeEnd = 1.f;
// colorLayer.mask = circle;

}

  • (CAShapeLayer *)LayerWithCircleCenter:(CGPoint)point
    radius:(CGFloat)radius
    startAngle:(CGFloat)startAngle
    endAngle:(CGFloat)endAngle
    clockwise:(BOOL)clockwise
    fillColor:(UIColor*)fillColor
    lineDashPattern:(NSArray *)lineDashPattern
    {
    CAShapeLayer *layer = [CAShapeLayer layer];

    // 贝塞尔曲线(创建一个圆)
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:point
    radius:radius
    startAngle:startAngle
    endAngle:endAngle
    clockwise:clockwise];

    // 获取path
    layer.path = path.CGPath;
    layer.position = point;

    // 设置填充颜色为透明
    layer.fillColor = fillColor.CGColor;

    // 获取曲线分段的方式
    if (lineDashPattern)
    {
    layer.lineDashPattern = lineDashPattern;
    }

    return layer;
    }

  • (void)drawCircleLine: (CALayer )layer withlineWidth: (CGFloat)width withLineColor: (UIColor )lineColor withFillColor: (UIColor *)fillColor withFrame :(CGRect)frame
    {
    CAShapeLayer *solidLine = [CAShapeLayer layer];
    CGMutablePathRef solidPath = CGPathCreateMutable();
    solidLine.lineWidth = width ;
    solidLine.strokeColor = lineColor.CGColor;
    solidLine.fillColor = fillColor.CGColor;
    CGPathAddEllipseInRect(solidPath, nil, frame);
    solidLine.path = solidPath;
    CGPathRelease(solidPath);
    [layer addSublayer:solidLine];
    }

  • (void)drawArcLine: (CALayer )layer withlineWidth: (CGFloat)width withLineColor: (UIColor )lineColor withFillColor: (UIColor *)fillColor withFrame :(CGRect)frame
    {
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
    //设置画笔颜色:黑色
    CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);
    //设置画笔线条粗细
    CGContextSetLineWidth(context, 0.6);

    //扇形参数
    double radius=40;//半径
    int startX=50;//圆心x坐标
    int startY=50;//圆心y坐标
    double pieStart=0;//起始的角度
    double pieCapacity=60;//角度增量值
    int clockwise=0;//0=逆时针,1=顺时针

    //逆时针画扇形
    CGContextMoveToPoint(context, startX, startY);
    CGContextAddArc(context, startX, startY, radius, radians(pieStart), radians(pieStart+pieCapacity), clockwise);
    CGContextClosePath(context);
    CGContextDrawPath(context, kCGPathEOFillStroke);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值