IOS之以UIBezierPath绘制饼状图

1.绘制的饼状图是通过多个扇形拼和而成,绘制一个扇形也是比较简单的,核心代码如下:


先画一条圆弧,再画半径,接着再画一条圆弧,最后闭合路径;

  1. UIBezierPath*  aPath = [[UIBezierPath alloc] init];  
  2.         [aPath moveToPoint:point2];  
  3.         [aPath addArcWithCenter:_centerPoint radius:_radius startAngle:RADIUS_TO(r.start) endAngle:RADIUS_TO(r.end) clockwise:YES];  
  4.         [aPath addLineToPoint:point];  
  5.         [aPath addArcWithCenter:_centerPoint radius:0.5 * _radius startAngle:RADIUS_TO(r.end) endAngle:RADIUS_TO(r.start) clockwise:NO];  
  6.         [aPath closePath];  


绘制完成后给整个路径添加填充颜色即可,效果如下:




2.给饼图添加点击响应事件,实现原理是根据点击点的坐标计算位于饼图的什么区域,以做出相应的响应;


效果如下:




最后是工程的源码,http://download.csdn.net/detail/xyybaozhen/8073377点击打开链接

posted @ 2016-10-14 14:09  brave-sailor  阅读(948)  评论(0编辑  收藏  举报