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


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

[objc] view plain copy
  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];  


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

IOS之以UIBezierPath绘制饼状图


IOS之以UIBezierPath绘制饼状图


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


效果如下:


IOS之以UIBezierPath绘制饼状图


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

相关文章:

  • 2022-02-06
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-10
  • 2021-05-17
  • 2022-12-23
  • 2021-12-06
  • 2022-01-23
  • 2021-04-05
  • 2021-04-14
相关资源
相似解决方案