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 ...
随机推荐
- AOP动态代理解析3-增强方法的获取
对于指定bean的增强方法的获取一定是包含两个步骤的: 获取所有的增强 寻找所有增强中使用于bean的增强并应用 那么findCandidateAdvisors与findAdvisorsThatCan ...
- node body-parser
var express = require('express'); var app = express(); var bodyParser = require('body-parser'); // p ...
- Delphi7 客户端调用WebService(天气预报)
客户程序:第一步:新建一个Application. 第二步:File----->New----->Other------>WebServices----->WSDL Impor ...
- CocoaPods安装和使用教程
Code4App 原创文章.转载请注明出处:http://code4app.com/article/cocoapods-install-usage 目录 CocoaPods是什么? 如何下载和安装Co ...
- UVa12264 Risk(最大流)
题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 每天一个linux命令---导出到文件
导出Linux下的部分日志到文件,使用‘>’符号 例如: [calendar@test190 logs]$ monitor.log|grep getCalendarView > share ...
- iOS学习08之C语言内存管理
本次主要学习和理解C语言中的内存管理 1.存储区划分 按照地址从高到低的顺序:栈区,堆区,静态区,常量区,代码区 1> 栈区:局部变量的存储区域 局部变量基本都在函数.循环.分支中定义 栈区的内 ...
- BZOJ4699 : 树上的最短路
这道题主要是要解决以下两个问题: 问题1: 给定一个点$x$,如何取出所有经过它的下水道? 一条下水道经过$x$等价于它起点在$x$的子树里面且终点不在$x$的子树里面,或者两端点的lca就是$x$. ...
- BZOJ3567 : AABB
考虑以块大小为$32$将序列分块,设$s[i][j]$表示前$i$块和前$j$块矩形相交的对数,$f[i][j]$表示矩形$i$和前$j$块的相交个数. 如果矩形$i$和$j$相交,那么有: $x_1 ...
- 栈式自动编码器(Stacked AutoEncoder)
起源:自动编码器 单自动编码器,充其量也就是个强化补丁版PCA,只用一次好不过瘾. 于是Bengio等人在2007年的 Greedy Layer-Wise Training of Deep Netw ...