Quartz2D学习笔记
1、drawRect方法
- //1.证明drawRect方法是在viewDidLoad后自动调用的,方便处理View的相关属性
- // YQView * view = [[YQView alloc] initWithFrame:self.view.bounds];
- //
- // [self.view addSubview:view];
- //2.init证明如果在初始化的时候没有设置rect的大小,将导致drawRect不能被自动调用
- // YQView * view = [[YQView alloc] init];
- //
- // [self.view addSubview:view];
- //3.手动调用drawRect
- self.customView = [[YQView alloc] initWithFrame:self.view.bounds];
- [self.view addSubview:self.customView];
- self.customView.iconImage = [UIImage imageNamed:@"1.jpg"];
- //调用这个方法会出错,不能手动调用,系统不允许直接调用
- // [self.customView drawRect:self.view.bounds];
- //当需要手动调用drawRect方法的时候,实际上就是通知父类重新绘图
- //setNeedsDisplay会异步自动调用drawRect方法
- [self.customView setNeedsDisplay];
2、绘制线段、三角形、矩形、(椭)圆形、扇形
- //1.画一条线段
- - (void)drawLine:(CGContextRef)contextRef
- {
- //先给一个起点
- CGContextMoveToPoint(contextRef, , );
- //再给一个终点
- CGContextAddLineToPoint(contextRef, , );
- //设置线的状态
- //线宽
- CGContextSetLineWidth(contextRef, );
- //颜色
- // CGContextSetRGBStrokeColor(contextRef, 0.4, 0.44, 0.99, 1.0);
- CGContextSetStrokeColorWithColor(contextRef, [UIColor redColor].CGColor);
- //风格设置
- // CGContextSetLineCap(contextRef, kCGLineCapRound);
- CGFloat lengths[] = {, , };
- /**
- * 绘制虚线
- *
- * @param c#> 作用域 description#>
- * @param phase#> 起点的左移量 description#>
- * @param lengths#> 实线和虚线的长度 description#>
- * @param count#> 实线和虚线的循环个数(count必须等于lengths数组的长度) description#>
- *
- * @return nil
- */
- CGContextSetLineDash(contextRef, , lengths, );
- //将图形绘制到view上面来(渲染)
- CGContextStrokePath(contextRef);
- }
- //2.画三角形
- - (void)drawTriangle:(CGContextRef)contextRef
- {
- CGContextMoveToPoint(contextRef, , );
- CGContextAddLineToPoint(contextRef, , );
- //如果连续添加多条线,它会把上一条线的终点作为下一条线的起点(即折线)
- CGContextAddLineToPoint(contextRef, , );
- //连接起点和终点(封起来)
- CGContextClosePath(contextRef);
- // CGContextAddLineToPoint(contextRef, 0, 0);
- //线宽
- CGContextSetLineWidth(contextRef, );
- //线的风格(拐角的风格)
- CGContextSetLineJoin(contextRef, kCGLineJoinRound);
- //
- CGContextSetStrokeColorWithColor(contextRef, [UIColor redColor].CGColor);
- //绘制边框内容
- // CGContextStrokePath(contextRef);
- //设置填充色
- CGContextSetFillColorWithColor(contextRef, [UIColor grayColor].CGColor);
- //绘制实心内容
- CGContextFillPath(contextRef);
- }
- //3.画矩形
- - (void)drawRectangle:(CGContextRef)contextRef
- {
- CGContextAddRect(contextRef, CGRectMake(, , , ));
- CGContextSetStrokeColorWithColor(contextRef, [UIColor yellowColor].CGColor);
- CGContextSetLineWidth(contextRef, );
- //空心的(画线轨迹)
- // CGContextStrokePath(contextRef);
- CGContextSetFillColorWithColor(contextRef, [UIColor greenColor].CGColor);
- //实心的
- // CGContextFillPath(contextRef);
- //同时显示线框和填充
- CGContextDrawPath(contextRef, kCGPathFillStroke);
- //以上三种渲染方式,只能使用一种,如果都写,只执行最先写的那个
- }
- //4.画圆(椭圆)
- - (void)drawCircle:(CGContextRef)contextRef
- {
- CGContextAddEllipseInRect(contextRef, CGRectMake(, , , ));
- CGContextFillPath(contextRef);
- }
- //5.扇形
- - (void)drawArc:(CGContextRef)contextRef
- {
- // CGContextMoveToPoint(contextRef, 100, 100);
- /**
- * 画扇形
- *
- * @param contextRef 作用域
- * @param x#> 原点x值(圆心) description#>
- * @param y#> 原点y值(圆心) description#>
- * @param radius#> 半径 description#>
- * @param startAngle#> 开始的角度 description#>
- * @param endAngle#> 结束的角度 description#>
- * @param clockwise#> 方向(默认0顺时针) description#>
- *
- * @return nil
- */
- // CGContextAddArc(contextRef, 100, 100, 50, 0, M_PI_2, 0);
- //
- // CGContextAddLineToPoint(contextRef, 100, 100);
- //
- // CGContextStrokePath(contextRef);
- CGContextFillPath(contextRef);
- //
- //1.第一部分
- CGContextMoveToPoint(contextRef, , );
- CGContextAddArc(contextRef, , , , , * M_PI / , );
- CGContextSetFillColorWithColor(contextRef, [UIColor cyanColor].CGColor);
- CGContextFillPath(contextRef);
- //2.第二部分
- CGContextMoveToPoint(contextRef, , );
- CGContextAddArc(contextRef, , , , , * M_PI / , );
- CGContextSetFillColorWithColor(contextRef, [UIColor magentaColor].CGColor);
- CGContextFillPath(contextRef);
- CGContextMoveToPoint(contextRef, , );
- CGContextAddArc(contextRef, , , , * M_PI / , * M_PI / , );
- CGContextSetFillColorWithColor(contextRef, [UIColor yellowColor].CGColor);
- CGContextFillPath(contextRef);
- }
Quartz2D学习笔记的更多相关文章
- Quartz2D学习笔记(1)
********************************** 简介 *************************************** Quartz2D是⼀个二维绘图引擎,同时支持 ...
- iOS学习笔记-精华整理
iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...
- iOS学习笔记总结整理
来源:http://mobile.51cto.com/iphone-386851_all.htm 学习IOS开发这对于一个初学者来说,是一件非常挠头的事情.其实学习IOS开发无外乎平时的积累与总结.下 ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- PHP-自定义模板-学习笔记
1. 开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2. 整体架构图 ...
- PHP-会员登录与注册例子解析-学习笔记
1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...
- 2014年暑假c#学习笔记目录
2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...
- JAVA GUI编程学习笔记目录
2014年暑假JAVA GUI编程学习笔记目录 1.JAVA之GUI编程概述 2.JAVA之GUI编程布局 3.JAVA之GUI编程Frame窗口 4.JAVA之GUI编程事件监听机制 5.JAVA之 ...
- seaJs学习笔记2 – seaJs组建库的使用
原文地址:seaJs学习笔记2 – seaJs组建库的使用 我觉得学习新东西并不是会使用它就够了的,会使用仅仅代表你看懂了,理解了,二不代表你深入了,彻悟了它的精髓. 所以不断的学习将是源源不断. 最 ...
随机推荐
- C#基础课程之五集合(HashTable,Dictionary)
HashTable例子: #region HashTable #region Add Hashtable hashTable = new Hashtable(); Hashtable hashTabl ...
- Java知多少(105)套接字(Socket)
网络应用模式主要有: 主机/终端模式:集中计算,集中管理: 客户机/服务器(Client/Server,简称C/S)模式:分布计算,分布管理: 浏览器/服务器模式:利用Internet跨平台. www ...
- js转html实体
方法一: 用的浏览器内部转换器实现转换,方法是动态创建一个容器标签元素,如DIV,将要转换的字符串设置为这个元素的innerText,然后返回这个元素的innerHTML,即得到经过HTML编码转换的 ...
- JS基础回顾,小练习(判断数组,以及函数)
追梦子博客版权所有. // 判断arr是否为一个数组,返回一个bool值 方法1: function isArray(arr) { var str = arr.__proto__.constructo ...
- ruby -- 进阶学习(十五)friendly_id配置
实现效果:http://127.0.0.1:3000/article/1 => http://127.0.0.1:3000/article/书名 (1)Rails 4.0的friendly_ ...
- [OpenCV] Feature Matching
得到了杂乱无章的特征点后,要筛选出好的特征点,也就是good matches. BruteForceMatcher FlannBasedMatcher 两者的区别:http://yangshen998 ...
- Bucky – 免费开源的实时用户监控工具
Bucky 是一个开源的实时用户监控工具,用于衡量用户在浏览器中使用 Web 应用程序时的性能.它可以自动测量你的网页需要多长时间来加载,Ajax 请求需要多长时间和各个函数需要实行多久. 您可能感兴 ...
- [Python]同是新手的我,分享一些经验
本来想分享一些知识,但是发现,写着写着,感觉分享一些经验,或许会少让大家走一些弯路,索性就把标题一改. 我不是教给大家些什么,我没有资格,我也是摸着石头过河,我只是本着分享的精神,在这里分享自己的东西 ...
- Linux下修改PATH路径
1.#PATH=$PATH:/opt/lamp/mysql/bin 使用这种方法,只对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效 2.#vi /etc/profi ...
- CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\helloiis\ceb8cab3\4db603d8\App_global.asax.gr73hi-k.dll”--“拒绝访问。 ”
我的报错页面: 我是使用的第一种方法解决的. 转至http://blog.csdn.net/zyzlywq/article/details/17916799 解决方法: 1,通常的解决方法:原因是由于 ...