iOS 画饼图
来源:互联网 发布:dns的端口号是 编辑:程序博客网 时间:2024/06/05 20:31
效果图:
核心代码:
#import "PieView.h"@implementation PieView- (void)drawRect:(CGRect)rect { // Drawing code NSArray *dataArray = @[@25,@25,@15,@15,@10,@10]; CGPoint center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5); CGFloat radius = self.bounds.size.width * 0.5 - 10; CGFloat startA = 0; CGFloat angle = 0; CGFloat endA = 0; for (NSNumber *num in dataArray) { startA = endA; angle = num.intValue / 100.0 * M_PI * 2; endA = startA + angle; UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; [[self randomColor] set]; //添加一根线到圆心 [path addLineToPoint:center]; [path fill]; }}-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //重绘 [self setNeedsDisplay];}//生成一个随机的颜色- (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];}//一个一个的画- (void)drawPie{ //画第一个扇形 CGPoint center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5); CGFloat radius = self.bounds.size.width * 0.5 - 10; CGFloat startA = 0; CGFloat angle = 25 / 100.0 * M_PI * 2; CGFloat endA = startA + angle; UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; [[UIColor redColor] set]; //添加一根线到圆心 [path addLineToPoint:center]; [path fill]; //画第二个扇形 startA = endA; angle = 25 / 100.0 * M_PI * 2; endA = startA + angle; path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; [[UIColor greenColor] set]; //添加一根线到圆心 [path addLineToPoint:center]; [path fill]; startA = endA; angle = 50 / 100.0 * M_PI * 2; endA = startA + angle; path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; [[UIColor blueColor] set]; //添加一根线到圆心 [path addLineToPoint:center]; [path fill];}@end
阅读全文
0 0
- iOS之画饼图
- iOS 画饼状图
- iOS 画饼图
- 三 iOS之 画饼图
- iOS 数组~画饼图-添加数据优化
- 画饼图
- 画饼图
- 画饼图
- 画饼图
- IOS开发-画饼图画柱状图
- asp.net画饼图
- Pie画饼图
- Flot画饼图
- asp.net画饼图
- 利用JqPlot画饼图
- 使用QPainter 画饼图
- 利用applet画饼图
- zedGraph画饼图
- Web实时通信Socket.IO兼容浏览器版本IE7&IE8&IE9&IE10
- 阿里巴巴编程题-兔子繁殖
- MySQL操作命令
- 第六篇:IP协议、ARP协议、RARP协议
- 每天一个linux命令(3):pwd命令
- iOS 画饼图
- 主成分分析法
- 第七篇:ICMP协议、Ping、Traceroute
- JavaScript的Math对象
- Android开发者e周报 第3期
- CDH版本离线安装的几个步骤
- linux连接外网
- 每天一个linux命令(4):mkdir命令
- Android softkeyboard 和 其他界面关系 softInputMode