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学习笔记的更多相关文章

  1. Quartz2D学习笔记(1)

    ********************************** 简介 *************************************** Quartz2D是⼀个二维绘图引擎,同时支持 ...

  2. iOS学习笔记-精华整理

    iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...

  3. iOS学习笔记总结整理

    来源:http://mobile.51cto.com/iphone-386851_all.htm 学习IOS开发这对于一个初学者来说,是一件非常挠头的事情.其实学习IOS开发无外乎平时的积累与总结.下 ...

  4. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  5. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  6. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  7. 2014年暑假c#学习笔记目录

    2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...

  8. JAVA GUI编程学习笔记目录

    2014年暑假JAVA GUI编程学习笔记目录 1.JAVA之GUI编程概述 2.JAVA之GUI编程布局 3.JAVA之GUI编程Frame窗口 4.JAVA之GUI编程事件监听机制 5.JAVA之 ...

  9. seaJs学习笔记2 – seaJs组建库的使用

    原文地址:seaJs学习笔记2 – seaJs组建库的使用 我觉得学习新东西并不是会使用它就够了的,会使用仅仅代表你看懂了,理解了,二不代表你深入了,彻悟了它的精髓. 所以不断的学习将是源源不断. 最 ...

随机推荐

  1. Qt5 从头学(2)--手动构建HelloWold

    在上一篇随笔中已经搭建好了Qt5的的开发环境,并且通过Qt Creator自动构建了一个视窗程序.在这篇文章中我们将手动编写一个HelloWold程序,简单了解一下Qt的构建过程.这里我们不会涉及到Q ...

  2. undefined function mysql_connect()解决方法

    在配置apache+php+mysql后,打开一个php网页文件正常,但是php网页中连接数据库时,出现以下提示: Fatal error: Call to undefined function my ...

  3. Machine Learning : Pre-processing features

    from:http://analyticsbot.ml/2016/10/machine-learning-pre-processing-features/ Machine Learning : Pre ...

  4. 使用tomcat作为web应用容器时,启用新线程找不到Session的问题

    今天做一个功能,为了快速响应前端,业务完成后,另起了一个线程做一些不影响业务的统计工作,然后立即将业务操作结果返回给前台. 结果在新线程里报空指针找不到request对象.检查了下,我们用的是stru ...

  5. android 视频的缩略图 缓存机制和 异步加载缩略图

    在这次的工作开发项目中,涉及到一个视频缩略图的视频列表:这个在大家看来,制作视频缩略图就是两行代码就搞定的事.确实是这样的,百度一下,每个帖子都知道制作视频缩略图的方法,在这里确实也是一样的,但是我要 ...

  6. Github教程(3)

    Pull Request Pull Request 是自己修改源代码后,请求对方仓库采纳该修改时采取的一种行为. 场景1: 用户A在fork完用户B的项目时,A修改了代码并提交了一个Pull Requ ...

  7. C#类的继承相关总结

    1.子类继承父类,会拥有父类中所规范的所有成员,但是只能是使用其中的公共成员 2.实现了继承,可以做到代码的冗余,做到代码的重用 3.实现了继承,可以方便代码的扩展与修改 4,当子类拥有与父类相同签名 ...

  8. jquery选择器(原创)

    jquery选择器大方向可以分为这样: 下面我们先来看看基本选择器总的CSS选择器: 1.标签选择器: $("element") 其中,参数element,表示待查找的HTML标记 ...

  9. 设计模式--外观(Facade)模式

    Insus.NET在去年有写过一篇<软件研发公司,外观设计模式(Facade)>http://www.cnblogs.com/insus/archive/2013/02/27/293606 ...

  10. Jcrop简单实用

    今天有一个项目的功能需求 “在上传照片的时候能进行裁剪”,网上找了下,发现有Jcrop这款插件,自己试了下,感觉很不错,蛮好用的.又能增加用户体验,测试了兼容性也很好,所以在这里分享下 首先,可以到官 ...