iOS开发UI-Quartz2D what about Quartz2D ?and how to use it ?
来源:互联网 发布:学淘宝美工正规的学校 编辑:程序博客网 时间:2024/06/05 07:45
1.what about Quartz2D ?
1.1简介
1.2图形上下文
(输出目标可以是PDF文件、Bitmap或者显示器的窗口上)
1.3 how to use it 自定义view
1.3.1drawRect:
Quartz2D须知
CGContextRef ctx= UIGraphicsGetCurrentContext();
CGContextMoveToPoint(ctx,10,10);
CGContextAddLineToPoint(ctx,100,100);
CGContextStrokePath(ctx); //CGContextFillPath(ctx);
常用拼接路径函数
void CGContextMoveToPoint(CGContextRef c,CGFloat x,CGFloat y)
void CGContextAddLineToPoint(CGContextRef c,CGFloat x,CGFloat y)
void CGContextAddRect(CGContextRef c,CGRect rect)
void CGContextAddEllipseInRect(CGContextRef context,CGRect rect)
void CGContextAddArc(CGContextRef c,CGFloat x,CGFloat y,
CGFloat radius, CGFloat startAngle, CGFloat endAngle, intclockwise)
void CGContextDrawPath(CGContextRef c,CGPathDrawingMode mode)
void CGContextStrokePath(CGContextRef c)
void CGContextFillPath(CGContextRef c)
提示:一般以CGContextDraw、CGContextStroke、CGContextFill开头的函数,都是用来绘制路径的
1.3.2图形上下文栈的操作
void CGContextSaveGState(CGContextRef c)
void CGContextRestoreGState(CGContextRef c)
2.案例 基本图形绘制
2.1运行效果如下
2.2.实现步骤
2.2.1新建一个project,然后自定义一个view
2.2.2代码
#import "htingLineView.h"@implementation htingLineView// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect{ // Drawing code // 1.获得图形上下文 (c语言必须取得上下文 oc则不用) typedef struct CGContext *CGContextRef; CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接图形(路径) // 设置线段宽度(一定要在渲染的前面否则没有效果) CGContextSetLineWidth(ctx, 10); // 设置线段头尾部的样式 CGContextSetLineCap(ctx, kCGLineCapRound); // 设置线段转折点的样式 CGContextSetLineJoin(ctx, kCGLineJoinRound); /** 第1根线段 **/ // 设置颜色 CGContextSetRGBStrokeColor(ctx, 1, 0, 0, 1); // 设置一个起点 CGContextMoveToPoint(ctx, 10, 10); // 添加一条线段到(100, 100) CGContextAddLineToPoint(ctx, 100, 100); // 渲染一次(如果这里不渲染那么上面设置的颜色不会起效果,只会显示下面渲染的颜色,如果要设置颜色则必须每设置一次就渲染一次) CGContextStrokePath(ctx); //CGContextStrokePath这个方法是把路径以空心的形式显示出来 /** 第2根线段 **/ // 设置颜色 CGContextSetRGBStrokeColor(ctx, 0, 0, 1, 1); // 设置一个起点 CGContextMoveToPoint(ctx, 200, 190); // 添加一条线段到(150, 40) CGContextAddLineToPoint(ctx, 150, 40); CGContextAddLineToPoint(ctx, 120, 60); // 3.渲染显示到view上面 CGContextStrokePath(ctx);}@end
- iOS开发UI-Quartz2D what about Quartz2D ?and how to use it ?
- iOS开发KVC——what is about kvc and how to use it ? (总结更新版)
- IOS开发UI:Quartz2D的使用
- What is JNI Graphics and how to use it?
- What is reflection and how to use it in CSharp ?
- iOS开发-Quartz2D初识
- iOS开发 - Quartz2D绘图
- iOS开发 - Quartz2D绘图
- iOS开发 - Quartz2D绘图
- Introduction to COM - What It Is and How to Use It.(ZT)
- Introduction to COM - What It Is and How to Use It.
- Introduction to COM - What It Is and How to Use It.
- Introduction to COM - What It Is and How to Use It.
- iOS开发UI篇—Quartz2D使用(图片剪切)
- iOS开发UI篇—Quartz2D使用(矩阵操作)
- iOS开发UI篇—Quartz2D简单使用(画文字)
- iOS开发UI篇—Quartz2D使用(绘图路径)
- iOS开发UI篇—Quartz2D使用(信纸条纹)
- apk反编译
- 以太网PHY 芯片之 MII/MDIO接口详解
- Virtual Box安装linux mint
- 文件加密之异或加密(C++实现)
- 数字倒序输出
- iOS开发UI-Quartz2D what about Quartz2D ?and how to use it ?
- linux下编译使用ffmpeg
- 全局认识运筹学
- A and B and Team Training——求最大组队数
- 99乘法表
- 嵌入式内核制作
- 黑马程序员---类的深入了解
- Codeforces 335B Palindrome 鸽巢原理 + DP
- PHP大神的十大优良习惯