IOS第16天(3,Quartz2D饼图)
****
#import "HMPieView.h"
#import "UIColor+Random.h"
@implementation HMPieView - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code NSArray *data = @[@,@,@]; // 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
CGPoint center = CGPointMake(, );
CGFloat radius = ;
CGFloat startA = ;
CGFloat angle = ;
CGFloat endA = ; for (NSNumber *number in data) {
// 2.拼接路径
startA = endA;
angle = number.intValue / 100.0 * M_PI * ;
endA = startA + angle;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
[path addLineToPoint:center]; [[UIColor randomColor] set];
// 把路径添加上下文
CGContextAddPath(ctx, path.CGPath); // 渲染
CGContextFillPath(ctx); } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGFloat a = arc4random_uniform();
//CGFloat a = arc4random()%6;
NSLog(@"随机数--%f",a); [self setNeedsDisplay];
} - (void)drawPie
{
// 1.获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
CGPoint center = CGPointMake(, );
CGFloat radius = ;
CGFloat startA = ;
CGFloat angle = ;
CGFloat endA = ; // 第一个扇形
angle = / 100.0 * M_PI * ;
endA = startA + angle;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
[path addLineToPoint:center];
// 添加到上下文
CGContextAddPath(ctx, path.CGPath);
[[UIColor redColor] set]; // 渲染
CGContextFillPath(ctx); // 第二个扇形
startA = endA;
angle = / 100.0 * M_PI * ;
endA = startA + angle;
UIBezierPath *path1 = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
[path1 addLineToPoint:center];
// 添加到上下文
CGContextAddPath(ctx, path1.CGPath);
[[UIColor greenColor] set];
// 渲染
CGContextFillPath(ctx); // 第三个扇形
startA = endA;
angle = / 100.0 * M_PI * ;
endA = startA + angle;
UIBezierPath *path2 = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
[path2 addLineToPoint:center];
// 添加到上下文
CGContextAddPath(ctx, path2.CGPath);
[[UIColor blueColor] set];
// 渲染
CGContextFillPath(ctx); } @end
IOS第16天(3,Quartz2D饼图)的更多相关文章
- IOS第16天(5,Quartz2D雪花)
*** #import "HMView.h" @interface HMView() { int count; } @property (nonatomic, assign) CG ...
- IOS第16天(4,Quartz2D柱状图)
*** #import "HMBarView.h" #import "UIColor+Random.h" @implementation HMBarView - ...
- IOS第16天(2,Quartz2D下载进度条)
*************自定义下载的view的方法 #import "HMProgressView.h" @interface HMProgressView() @propert ...
- IOS第16天(1,Quartz2D基本图像绘制)
***************基本图像绘制 画线 #import "HMLineView.h" @implementation HMLineView - (id)initWithF ...
- iOS根据16进制的色号来设置颜色,适合封装工具类
iOS中有时候UI给的一个色号就像 #54e1b7 这个,而我们一般设置颜色都是根据RBG来设置的,所以这里需要把这个16进制的色号转为RGB值,这里我们就使用一下的方法来调用设置颜色. + (UIC ...
- [Draft]iOS.Architecture.16.Truth-information-flow-and-clear-responsibilities-immutability
Concept: Truth, Information Flow, Clear Responsibilities and Immutability 1. Truth 1.1 Single Source ...
- [iOS]把16进制(#871f78)颜色转换UIColor
// // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...
- 【转】iOS中16进制转10进制
原文网址:http://www.voidcn.com/blog/u012198553/article/p-4976772.html /// 将十六进制的字符串转化为NSData - (NSData ) ...
- iOS UI进阶-1.0 Quartz2D
概述 Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统.Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成PDF ...
随机推荐
- 解决Kali Linux没有声音
解决Kali Linux没有声音 Kali Linux系统默认状态下,root用户是无法使用声卡的,也就没有声音.启用的方法如下: (1)在终端执行命令:systemctl --user enab ...
- BOM和DOM的区别和关联
BOM 1. BOM是Browser Object Model的缩写,即浏览器对象模型. 2. BOM没有相关标准. 3. BOM的最根本对象是window. 从1可以看出来:BOM和浏览器关系密切. ...
- Docker安装RStudio
在我前一篇文章中已讲述了如何在Windows中安装和配置Docker,本文则讲述如何在docker中安装rstudio! 1.Docker的使用 1.1查看指定machine的IP 打开Docker ...
- [R语言]forecast.Arima中使用xreg报错
问题: 使用forecast.Arima对带xreg的arima模型进行预测,报xreg Error pre.m4x <- forecast.Arima(m4x, h = 20, xreg = ...
- 使用Percona Toolkit解决Mysql主从不同步问题【备忘】
由于各种原因,mysql主从架构经常会出现数据不一致的情况出现,大致归结为如下几类 1:备库写数据 2:执行non-deterministic query 3:回滚掺杂事务表和非事务表的事务 4:bi ...
- 【HDU】2147 kiki's game
http://acm.hdu.edu.cn/showproblem.php?pid=2147 题意:n×m的棋盘,每次可以向左走.向下走.向左下走,初始在(1, m),n,m<=2000,问先手 ...
- POJ 2420 A Star not a Tree?(模拟退火)
题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...
- asp.net mvc4 HTTP Error 403.14
asp.net mvc4项目部署到II&上时,出现HTTP Error 403.14 - Forbidden - The Web server is configured to not lis ...
- SVN错误:Attempted to lock an already-locked dir
在eclipse里提交和更新文件是报错: Attempted to lock an already-locked dir svn: Working copy 'F:\workspace\WebFram ...
- JS中常遇到的浏览器兼容问题和解决方法【转】
今天整理了一下浏览器对JS的兼容问题,希望能给你们带来帮助,我没想到的地方请留言给我,我再加上: 常遇到的关于浏览器的宽高问题: //以下均可console.log()实验 var winW=docu ...