UIKit和Core Graphics绘图(三)——绘制虚线,椭圆以及饼图
绘制虚线
- (void)drawLineDash
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetLineWidth(context, 2.0f);
CGContextSetLineDash(context, 0, (CGFloat[]){10, 5}, 2);//绘制10个跳过5个
CGContextSetStrokeColorWithColor(context, [[UIColor brownColor] CGColor]);
CGContextMoveToPoint(context, 0, 20);
CGContextAddLineToPoint(context, 320, 20);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
效果如下:
绘制椭圆与圆
- (void)drawEllipse
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextAddEllipseInRect(context, CGRectMake(40, 180, 240, 120));
CGContextSetLineWidth(context, 3.0f);
CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
效果
绘制弧,饼图(Pie Chart)
CGContextRef c,
CGFloat x,圆心点坐标的x和y
CGFloat y,
CGFloat radius,半径
CGFloat startAngle,绘制起始点的弧度值,一般在IOS绘图里都使用弧度这个概念
int clockwise1为顺时针,0为逆时针。
);
void drawPieChart(CGContextRef context, CGPoint point, float start_angel, float end_angle, double radius, CGColorRef color)
{
CGContextMoveToPoint(context, point.x, point.y);
CGContextSetFillColorWithColor(context, color);
CGContextAddArc(context, point.x, point.y, radius, start_angel, end_angle, 0);
CGContextFillPath(context);
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
// [self drawLineDash];
// [self drawEllipse]; CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetShadow(context, CGSizeMake(0, 10), 10); //简单的设置了一个阴影
double radius = 120; float start = RADIANS(0);
float end = RADIANS(120);
drawPieChart(context, self.center, start, end, radius, [[UIColor orangeColor] CGColor]); start = end;
end = RADIANS(194);
drawPieChart(context, self.center, start, end, radius, [[UIColor yellowColor] CGColor]); start = end;
end = RADIANS(231);
drawPieChart(context, self.center, start, end, radius, [[UIColor purpleColor] CGColor]); start = end;
end = RADIANS(360);
drawPieChart(context, self.center, start, end, radius, [[UIColor blueColor] CGColor]); CGContextRestoreGState(context);
}
UIKit和Core Graphics绘图(三)——绘制虚线,椭圆以及饼图的更多相关文章
- UIKit和Core Graphics绘图(一)——字符串,线条,矩形,渐变
概述 CoreGraphics也称为Quartz 2D 是UIKit下的主要绘图系统,频繁的用于绘制自定义视图.Core Graphics是高度集成于UIView和其他UIKit部分的.Core Gr ...
- iOS绘图系统UIKit与Core Graphics
概述 iOS主要的绘图系统有UIKit,Core Graphics,Core Animation,Core Image,Open GL等,本片博文主要介绍UIKit与Core Graphics的绘图系 ...
- iOS 使用drawRect: 绘制虚线椭圆
iOS 使用drawRect: 绘制虚线椭圆 1:首先如果要使用 drawRect 绘图 要导入 CoreGraphics.framework 框架 然后 创建 自定义view, 即是 myView继 ...
- iOS实现图形编程可以使用三种API(UIKIT、Core Graphics、OpenGL ES及GLKit)
这些api包含的绘制操作都在一个图形环境中进行绘制.一个图形环境包含绘制参数和所有的绘制需要的设备特定信息,包括屏幕图形环境.offscreen 位图环境和PDF图形环境,用来在屏幕表面.一个位图或一 ...
- Core Graphics绘图
首先了解一下CGContextRef: An opaque type that represents a Quartz 2D drawing environment. Graphics Context ...
- Cocoa Touch(三):图形界面UIKit、Core Animation、Core Graphics
UIKit 视图树模型 1.视图树模型 计算机图形实际上是一个视图树模型,每个视图都有一个本地坐标系.每个本地坐标系的组成部分是:原点在父坐标系中的位置,每个基在父坐标系中的位置,由此就可以根据向量的 ...
- Core Graphics框架 利用Quartz 2D绘图
首先,什么是Core Graphics和Quartz 2D? Core Graphics:是基于Quartz 2D绘图引擎的一个C语言的API绘图框架.它也是iOS开发中最基本的框架(Framewor ...
- iOS 图形处理 Core Graphics Quartz2D 教程
Core Graphics Framework是一套基于C的API框架,使用了Quartz作为绘图引擎.它提供了低级别.轻量级.高保真度的2D渲染.该框架可以用于基于路径的 绘图.变换.颜色管理.脱屏 ...
- Core Graphics框架
在iOS中常用的框架是Quartz 2D,它是Core Graphics框架的一部分,是一个强大的二维图像绘制引擎.我们日常开发所用到的UIKit的组件都是由Core Graphics框架进行绘制的. ...
随机推荐
- C++11中正則表達式測试
VC++2010已经支持regex了, 能够用来编译下述代码. #include <string> #include <regex> #include <iostream ...
- c语言10个经典小程序
[程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 1.程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不满足条件的排列. ...
- Gstreamer 中的playback插件
1. PLAYBACK插件基本介绍 在早期的版本中同时存在playbin和playbin2,但是在最新的版本中,playbin2已经稳定,取代了playbin, playbin不再进行维护.下面是官网 ...
- javascsript 去除数组重复数据
function uniqid(arr){ var newArr = []; var c; for(var i = 0 ;i <= arr.length ;i++){ c = false; fo ...
- 当chm文档点击左侧,右侧无内容时的解决方案
右击chm文件->属性->安全选项卡,选择你登陆计算机的用户名,把权限改成完全控制就可以显示了
- android 5.0 受欢迎的API简介
android 5.0 作为系统的一次重大升级,给用户和开发者带来了全新的体验.Material Design不但在视觉和操作上更胜一筹,扩展UI工具包同时也引入了大量新的API. 1. 3D视图和实 ...
- 文件:一个任务 - 零基础入门学习Python029
文件:一个任务 让编程改变世界 Change the world by program 一个任务 这节课,我们需要一起来完成一个任务:将文件(record.txt)中的数据进行分割并按照以下规律保存起 ...
- Nasty Hacks <入门练手题>
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- SQLServer中数据库文件的存放方式,文件和文件组
我们公司近一年来做了一个CRM系统. 遇到一个问题就是:在插入交流记录的时候速度特别慢.(交流记录数据量大) 后来我们经理采用文件组的方法,将客户交流记录这张表提出来就快很多了 这里有一篇关于文件组的 ...
- Core Data (二)备
序 上次只是说了三个Core Data栈基本类.这次准备介绍一下常用的类. NSManagedObject Core Data是一次底层数据封装成面向对象的技术.最直接的表现就是在SQLite里面的一 ...