#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];
}
}