本文是利用UIBezierPath来绘制的,从圆顶点-M_PI_2,顺时针累加每个扇形的角度。我这里的动画是利用定时器实现的,如果想做成环形饼图可以在中间再画一个圆,下面贴出核心代码
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.pieView];
startAngle = -M_PI_2;
self.count = 0;
self.timer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(timerMethod) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)timerMethod{
CGSize size = self.pieView.frame.size;
if (self.count < self.colorArray.count) {
[self drawPieLayer:CGPointMake(size.width/2, size.height/2) radius:size.height/2];
self.count += 1;
}else{
[self.timer invalidate];
self.timer = nil;
}
}
/**
绘制饼图
@pa