1.绘制的饼状图是通过多个扇形拼和而成,绘制一个扇形也是比较简单的,核心代码如下:
先画一条圆弧,再画半径,接着再画一条圆弧,最后闭合路径;
- UIBezierPath* aPath = [[UIBezierPath alloc] init];
- [aPath moveToPoint:point2];
- [aPath addArcWithCenter:_centerPoint radius:_radius startAngle:RADIUS_TO(r.start) endAngle:RADIUS_TO(r.end) clockwise:YES];
- [aPath addLineToPoint:point];
- [aPath addArcWithCenter:_centerPoint radius:0.5 * _radius startAngle:RADIUS_TO(r.end) endAngle:RADIUS_TO(r.start) clockwise:NO];
- [aPath closePath];
2.给饼图添加点击响应事件,实现原理是根据点击点的坐标计算位于饼图的什么区域,以做出相应的响应;
效果如下:
最后是工程的源码,http://download.csdn.net/detail/xyybaozhen/8073377点击打开链接