分段划曲线
思路
将第一段的终值赋值给第二段的初始值,以此类推。。。
2.[self
setNeedsDisplay]更新画图进度
代码示例
#import <UIKit/UIKit.h>
#import "HXProgressColorAndRateModel.h"
@interface PieProgressView : UIView
@property(
nonatomic,
strong)
NSMutableArray *colors;
@property(
nonatomic,
strong)
UIColor *defaultColor;
-(
void)setProgressWithAnimated;
@end
#import "PieProgressView.h"
#import <QuartzCore/QuartzCore.h>
@interface PieProgressView()
@property(
nonatomic,
assign)
float start;
@property(
nonatomic,
assign)
float end;
@end
@implementation PieProgressView
-(
void)drawRect:(
CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
self.start = -M_PI_2;
CGPoint point = CGPointMake(
self.frame.size.width/
2,
self.frame.size.height/
2);
if (
self.colors&&
self.colors.count) {
for (
int i=
0; i<
self.colors.count; i++) {
HXProgressColorAndRateModel *model =
self.colors[i];
self.end=
self.start + model
.progressRate*
2*M_PI;
CGFloat endAngle =
self.end;
float radiusCircle =
self.frame.size.width>
self.frame.size.height?
self.frame.size.height/
2:
self.frame.size.width/
2;
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:point radius:(radiusCircle-
2) startAngle:
self.start endAngle:endAngle clockwise:
YES];
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetLineWidth(context,
4.0);
CGContextSetStrokeColorWithColor(context, model
.progressColor.CGColor);
CGContextAddPath(context, bezierPath
.CGPath);
CGContextStrokePath(context);
self.start =
self.end;
}
}
else{
CGFloat endAngle =
2*M_PI;
float radiusCircle =
self.frame.size.width>
self.frame.size.height?
self.frame.size.height/
2:
self.frame.size.width/
2;
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:point radius:(radiusCircle-
2) startAngle:
self.start endAngle:endAngle clockwise:
YES];
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetLineWidth(context,
4.0);
UIColor *deColor =
self.defaultColor?
self.defaultColor:[
UIColor whiteColor];
CGContextSetStrokeColorWithColor(context, deColor
.CGColor);
CGContextAddPath(context, bezierPath
.CGPath);
CGContextStrokePath(context);
}
}
-(
void)setProgressWithAnimated
{
self.hidden =
NO;
[
self setNeedsDisplay];
}
转载请注明原文地址: https://ju.6miu.com/read-22190.html