Quartz2D-06.利用贝瑟尔曲线画饼状图
2015-08-05 22:38
281 查看
效果图
代码实现
代码实现
#import "ZJCakeView.h" @implementation ZJCakeView - (void)drawRect:(CGRect)rect { // 计算需要的位置 CGFloat radius = self.bounds.size.width * 0.5; CGPoint center = CGPointMake(radius, self.bounds.size.height * 0.5); CGFloat statA = 0; CGFloat angle = 0; CGFloat endA = 0; NSArray *data = @[@20,@20,@35,@25]; // 根据传入的数据计算各个扇形的起始点 for (int i = 0; i < data.count; i++) { int num = [data[i] intValue]; statA = endA; angle = num/100.0 * M_PI * 2; endA = statA + angle; // 创建贝瑟尔路径 UIBezierPath *path = [UIBezierPath bezierPath]; [path addArcWithCenter:center radius:radius startAngle:statA endAngle:endA clockwise:YES]; [path addLineToPoint:center]; [[self randomColor] set]; [path fill]; } } // 随机颜色 -(UIColor *)randomColor{ CGFloat r = arc4random_uniform(256)/255.0; CGFloat g = arc4random_uniform(256)/255.0; CGFloat b = arc4random_uniform(256)/255.0; return [UIColor colorWithRed:r green:g blue:b alpha:1]; } @end
相关文章推荐
- Java 控制台读取输入并过滤特定字符
- Codeforces Round #Pi (Div. 2)
- git学习笔记
- 【linux高级程序设计】(第十五章)UDP网络编程应用 2
- Hadoop2.6.0学习笔记(五)MapReduce实现TopN
- YUV格式学习:NV16和YUV422P格式互换
- linux 进程间通信 使用信号量
- Android内核学习之二------JNI的使用
- struts2+spring的两种整合方式
- windowsphone8.1学习笔记之应用数据(一)
- 树莓派实战3:配置开机自启动
- WNDCLASS中cbClsExtra和cbWndExtra区别及其用法
- Java线程-----------线程安全与不安全与线程同步synchronized和volatile
- LeetCode 16 3Sum Closest
- iOS 8 AutoLayout与Size Class自悟
- CMD 使用emulator.exe启动Android模拟器——emulator -data 镜像文件名称
- Ubuntu 和 Redhat / Fedora 服务管理命令对比表(附Fedora16新的服务管理工具systemctl )
- Android - Fragment (三)不同Fragment之间的通信
- js中ajax的异步性
- (一〇八)iPad开发之横竖屏适配