- (void)setCurrentProgressWithIndex1:(float)index1 index2:(float)index2 index3:(float)index3 {
_index1 = index1;
_index2 = index2;
_index3 = index3;
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self drawProgressWithContext:ctx];
}
- (void)drawProgressWithContext:(CGContextRef)ctx {
float width = self.frame.size.width;
// index
float start_index = 0.0f;
if (_index1 != 0.0f) {
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
bezierPath.lineCapStyle = kCGLineCapRound;
bezierPath.lineJoinStyle = kCGLineJoinBevel;
[bezierPath moveToPoint: CGPointMake(start_index, 0)];
[bezierPath addLineToPoint: CGPointMake(start_index, 20)];
[bezierPath addLineToPoint: CGPointMake(start_index + width * _index1, 20)];
[bezierPath addLineToPoint: CGPointMake(start_index + width * _index1, 0)];
[UIColor.redColor setFill];
[bezierPath fill];
start_index += width * _index1;
}
if (_index2 != 0.0f) {
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
bezierPath.lineCapStyle = kCGLineCapRound;
bezierPath.lineJoinStyle = kCGLineJoinBevel;
[bezierPath moveToPoint: CGPointMake(start_index, 0)];
[bezierPath addLineToPoint: CGPointMake(start_index, 20)];
[bezierPath addLineToPoint: CGPointMake(start_index + width * _index2, 20)];
[bezierPath addLineToPoint: CGPointMake(start_index + width * _index2, 0)];
[UIColor.greenColor setFill];
[bezierPath fill];
start_index += width * _index2;
}
if (_index3 != 0.0f) {
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
bezierPath.lineCapStyle = kCGLineCapRound;
bezierPath.lineJoinStyle = kCGLineJoinBevel;
[bezierPath moveToPoint: CGPointMake(start_index, 0)];
[bezierPath addLineToPoint: CGPointMake(start_index, 20)];
[bezierPath addLineToPoint: CGPointMake(start_index + width * _index3, 20)];
[bezierPath addLineToPoint: CGPointMake(start_index + width * _index3, 0)];
[UIColor.blueColor setFillx];
[bezierPath fill];
}
}