iPhone 利用CG API画一个饼图(Pie chart) 百分比圆 以及 响应扇形点击事件
来源:互联网 发布:ip切换软件 编辑:程序博客网 时间:2024/04/23 23:48
核心函数是:CGContextAddArc(CGContextRef c, CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise) * CGContextRef: 图形上下文 * x,y: 开始画的坐标 * radius: 半径 * startAngle, endAngle: 开始的弧度,结束的弧度 * clockwise: 画的方向(顺时针,逆时针)
有了这个函数可以画出任意扇形,所以饼图也不再话下.
#define PI 3.14159265358979323846#define radius 100static inline float radians(double degrees) { return degrees * PI / 180; }static inline void drawArc(CGContextRef ctx, CGPoint point, float angle_start, float angle_end, UIColor* color) { CGContextMoveToPoint(ctx, point.x, point.y); CGContextSetFillColor(ctx, CGColorGetComponents( [color CGColor])); CGContextAddArc(ctx, point.x, point.y, radius, angle_start, angle_end, 0); //CGContextClosePath(ctx); CGContextFillPath(ctx); }- (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextClearRect(ctx, rect); float angle_start = radians(0.0); float angle_end = radians(121.0); drawArc(ctx, self.center, angle_start, angle_end, [UIColor yellowColor]); angle_start = angle_end; angle_end = radians(228.0); drawArc(ctx, self.center, angle_start, angle_end, [UIColor greenColor]); angle_start = angle_end; angle_end = radians(260); drawArc(ctx, self.center, angle_start, angle_end, [UIColor orangeColor]); angle_start = angle_end; angle_end = radians(360); drawArc(ctx, self.center, angle_start, angle_end, [UIColor purpleColor]);}
效果:
想想,我用这个函数,画两个同圆心的扇形
大的用自己想要的颜色,小的用背景色
这样就实现了画环形了,多谢大神!
我来补充点:可以使用UIBezierPath的处理扇形区域的点击事件
原文地址:http://www.devdiv.com/forum.php?mod=viewthread&tid=38136&fromuid=36506
- iPhone 利用CG API画一个饼图(Pie chart) 百分比圆 以及 响应扇形点击事件
- iPhone 利用CG API画一个饼图(Pie chart)
- iPhone 利用CG API画一个饼图(Pie chart) 可以用在很多地方 画弧线
- iphone 让一个UIImageView响应点击事件
- Android chart、图表、条形图、饼图 pie chart 等的实现及点击事件、监听器的实现 click ,achartengine
- Android chart、图表、条形图、饼图 pie chart 等的实现及点击事件、监听器的实现 click ,achartengine
- iphone--UIImageView响应点击事件
- 占百分比,扇形图
- 饼图中扇形点击事件方法
- Android 自定义View 慢慢画一个不同颜色扇形的圆,点击圆上不同颜色扇形区域返回不同颜色
- chart 图例点击事件
- 让一个UIImageView响应点击事件
- 让一个UIImageView响应点击事件
- 趣图:吃豆人相仿百分比扇形图
- c# 通过.net自带的chart控件绘制饼图pie chart
- c#通过.net自带的chart控件绘制饼图pie chart
- cocos2d-x 画实心圆以及扇形
- chart.js异步加载柱状图与饼图,柱状图添加点击事件,自定义柱状图的颜色
- Firefox 4中javascript脚本执行的变化
- AL32UTF8和UTF8字符集
- 手机产品设计之用户引导
- WIN7 home 如何开启administrator账户
- popupwindow 如何实现弹出菜单效果_popupwindow 实现弹出窗口范例
- iPhone 利用CG API画一个饼图(Pie chart) 百分比圆 以及 响应扇形点击事件
- 微软历史最高市值是多少?
- firefox常用快捷键集合
- linux下文件压缩与解压操作
- iPhone 短信音及显示名称更改方法
- Mule3配置文件
- 怎样设计一个合理的软件试用机制或类似机制?
- Delphi7 修改单元文件的名字
- windows 架设trac 服务器 -==- 集成subversion 和apache