关闭

iOS UIBezierPath图形绘制

标签: 图形
86人阅读 评论(0) 收藏 举报
分类:
#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];
    }
}

<img src="http://img.blog.csdn.net/20160601142453744?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" align="middle" alt="" />

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4855次
    • 积分:317
    • 等级:
    • 排名:千里之外
    • 原创:28篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类