iOS UIBezierPath图形绘制


#pragma mark - 绘制外圈路径
- (void)drawOuter:(CGRect)rect{
    
    UIColor *color = [UIColor colorWithRed:224/255.0f green:224/255.0f blue:224/255.0f alpha:1.0f];
    [color set]; //设置线条颜色
    
    UIBezierPath    *bPath = [UIBezierPath bezierPathWithArcCenter:_centerPoint
                                                            radius:_outerRadiusWidth-2
                                                        startAngle:M_PI
                                                          endAngle:2*M_PI
                                                         clockwise:YES];
    
    bPath.lineWidth = _outerWidth;
    bPath.lineCapStyle = kCGLineCapRound; //线条拐角
    bPath.lineJoinStyle = kCGLineCapRound; //终点处理
 }

#pragma mark - 绘制内圈进度路径
- (void)setInnerProgess{
    if (_shapeLayer) {
        [_shapeLayer removeFromSuperlayer];
    }
    _shapeLayer = [CAShapeLayer layer];
    _shapeLayer.strokeColor = [[TNColor ff6633Color] CGColor];
    _shapeLayer.fillColor = [[UIColor clearColor] CGColor];
    _shapeLayer.lineWidth = _innerWidth;
    _shapeLayer.lineCap = kCALineCapRound;
    _shapeLayer.lineJoin = kCALineJoinRound;
    _shapeLayer.path = [UIBezierPath bezierPathWithArcCenter:_centerPoint radius:_innerRadiusWidth startAngle:DEGREES_TO_RADIANS(_beginAngle) endAngle:DEGREES_TO_RADIANS(_rotationAngle) clockwise:YES].CGPath;
    [self.layer addSublayer:_shapeLayer];
}
#pragma mark - 绘制指示线
- (void)drawIndicatorLine{
    
    UIColor *color = [TNColor ff6633Color];
    [color set]; //设置线条颜色
    
    
    NSInteger  _total = 5;
    
    CGFloat x0 = _centerPoint.x;
    CGFloat y0 = _centerPoint.y;
    int i = 0;
    for (i = 0; i < _total; i++) {
        UIBezierPath *bezierPath = [UIBezierPath bezierPath];
        bezierPath.lineWidth = 2;
        
        CGFloat x1 = x0 + cosf(_startAngle + _totalAngle*i/(_total-1))*(_lineRadiusWidth-6);
        CGFloat y1 = y0+ sinf(_startAngle + _totalAngle*i/(_total-1))*(_lineRadiusWidth-6);
        
        CGFloat x2 = x0 + cosf(_startAngle + _totalAngle*i/(_total-1))*_lineRadiusWidth;
        CGFloat y2 = y0+ sinf(_startAngle + _totalAngle*i/(_total-1))*_lineRadiusWidth;
        
        [bezierPath moveToPoint:CGPointMake(x1, y1)];
        [bezierPath addLineToPoint:CGPointMake(x2, y2)];
        
        [bezierPath stroke];
    }
 
}

#pragma mark - 绘制文字
- (void)drawMothsLabel{
    [_mothsLabelArray removeAllObjects];
    
    for (int i = 0; i < _moths.count; i++) {
        NSString *mothInfo = _moths[i];
        
        CGFloat x0 = _centerPoint.x;
        CGFloat y0 = _centerPoint.y;
        CGFloat x = x0 + cosf(_startAngle + _totalAngle*i/(_moths.count-1))*_labelRadiusWidth;
        CGFloat y = y0+ sinf(_startAngle + _totalAngle*i/(_moths.count-1))*_labelRadiusWidth;
        CGRect rect = CGRectMake(x-30, y-20, 60, 25);
        
        CGFloat angleDegrees = 0;
        if (i==0) {
            angleDegrees = -90;
        }else if (i==1){
            angleDegrees = -45;
        }else if (i==2){
            angleDegrees = 0;
        }else if (i==3){
            angleDegrees = 45;
        }else if (i==4){
            angleDegrees = 90;
        }
        
        CATextLayer* textLayer = [[CATextLayer alloc] init];
        textLayer.string = mothInfo;
        textLayer.frame = rect;
        textLayer.alignmentMode = kCAAlignmentCenter;
        if ([_mothsArray[i] isEqualToString:@"1"]) {
            textLayer.foregroundColor =  [TNColor ff6633Color].CGColor;
        }else{
            textLayer.foregroundColor =  [UIColor lightGrayColor].CGColor;
        }
        
        textLayer.backgroundColor =  [UIColor clearColor].CGColor;
        textLayer.fontSize = 14.0f;
        textLayer.contentsScale = 2;
        [self.layer addSublayer:textLayer];
        textLayer.affineTransform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(angleDegrees));
        [_mothsLabelArray  addObject:textLayer];
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值