拷贝被人的drawRect绘图分类用途,用法很全。留着、供用时参考

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

CGContextRef context = UIGraphicsGetCurrentContext();

/*NO.1画一条线

CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色

CGContextMoveToPoint(context, 20, 20);

CGContextAddLineToPoint(context, 200,20);

CGContextStrokePath(context);

*/

/*NO.2写文字

CGContextSetLineWidth(context, 1.0);

CGContextSetRGBFillColor (context, 0.5, 0.5, 0.5, 0.5);

UIFont  *font = [UIFont boldSystemFontOfSize:18.0];

[@"公司:北京中软科技股份有限公司\n部门:ERP事业部\n姓名:McLiang" drawInRect:CGRectMake(20, 40, 280, 300) withFont:font];

*/

/*NO.3画一个正方形图形 没有边框

CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5);

CGContextFillRect(context, CGRectMake(2, 2, 270, 270));

CGContextStrokePath(context);

*/

/*NO.4画正方形边框

CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色

CGContextSetLineWidth(context, 2.0);

CGContextAddRect(context, CGRectMake(2, 2, 270, 270));

CGContextStrokePath(context);

*/

/*NO.5画方形背景颜色

CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);

CGContextScaleCTM(context, 1.0f, -1.0f);

UIGraphicsPushContext(context);

CGContextSetLineWidth(context,320);

CGContextSetRGBStrokeColor(context, 250.0/255, 250.0/255, 210.0/255, 1.0);

CGContextStrokeRect(context, CGRectMake(0, 0, 320, 460));

UIGraphicsPopContext();

*/

/*NO.6椭圆

CGRect aRect= CGRectMake(80, 80, 160, 100);

CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);

CGContextSetLineWidth(context, 3.0);

CGContextAddEllipseInRect(context, aRect); //椭圆

CGContextDrawPath(context, kCGPathStroke);

*/

/*NO.7

CGContextBeginPath(context);

CGContextSetRGBStrokeColor(context, 0, 0, 1, 1);

CGContextMoveToPoint(context, 100, 100);

CGContextAddArcToPoint(context, 50, 100, 50, 150, 50);

CGContextStrokePath(context);

*/

/*NO.8渐变

CGContextClip(context);

CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();

CGFloat colors[] =

{

204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00,

29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00,

0.0 / 255.0,  50.0 / 255.0, 126.0 / 255.0, 1.00,

};

CGGradientRef gradient = CGGradientCreateWithColorComponents

(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));

CGColorSpaceRelease(rgb);

CGContextDrawLinearGradient(context, gradient,CGPointMake

(0.0,0.0) ,CGPointMake(0.0,self.frame.size.height),

kCGGradientDrawsBeforeStartLocation);

*/

/* NO.9四条线画一个正方形

//画线

UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];

CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);

CGContextSetFillColorWithColor(context, aColor.CGColor);

CGContextSetLineWidth(context, 4.0);

CGPoint aPoints[5];

aPoints[0] =CGPointMake(60, 60);

aPoints[1] =CGPointMake(260, 60);

aPoints[2] =CGPointMake(260, 300);

aPoints[3] =CGPointMake(60, 300);

aPoints[4] =CGPointMake(60, 60);

CGContextAddLines(context, aPoints, 5);

CGContextDrawPath(context, kCGPathStroke); //开始画线

*/

/*  NO.10

UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];

CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);

CGContextSetFillColorWithColor(context, aColor.CGColor);

//椭圆

CGRect aRect= CGRectMake(80, 80, 160, 100);

CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);

CGContextSetLineWidth(context, 3.0);

CGContextSetFillColorWithColor(context, aColor.CGColor);

CGContextAddRect(context, rect); //矩形

CGContextAddEllipseInRect(context, aRect); //椭圆

CGContextDrawPath(context, kCGPathStroke);

*/

/*  NO.11

画一个实心的圆

CGContextFillEllipseInRect(context, CGRectMake(95, 95, 100.0, 100));

*/

/*NO.12

画一个菱形

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGContextMoveToPoint(context, 100, 100);

CGContextAddLineToPoint(context, 150, 150);

CGContextAddLineToPoint(context, 100, 200);

CGContextAddLineToPoint(context, 50, 150);

CGContextAddLineToPoint(context, 100, 100);

CGContextStrokePath(context);

*/

/*NO.13 画矩形

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGRect rectangle = CGRectMake(60,170,200,80);

CGContextAddRect(context, rectangle);

CGContextStrokePath(context);

*/

/*椭圆

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGRect rectangle = CGRectMake(60,170,200,80);

CGContextAddEllipseInRect(context, rectangle);

CGContextStrokePath(context);

*/

/*用红色填充了一段路径:

CGContextMoveToPoint(context, 100, 100);

CGContextAddLineToPoint(context, 150, 150);

CGContextAddLineToPoint(context, 100, 200);

CGContextAddLineToPoint(context, 50, 150);

CGContextAddLineToPoint(context, 100, 100);

CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);

CGContextFillPath(context);

*/

/*填充一个蓝色边的红色矩形

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGRect rectangle = CGRectMake(60,170,200,80);

CGContextAddRect(context, rectangle);

CGContextStrokePath(context);

CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);

CGContextFillRect(context, rectangle);

*/

/*画弧

//弧线的是通过指定两个切点,还有角度,调用CGContextAddArcToPoint()绘制

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGContextMoveToPoint(context, 100, 100);

CGContextAddArcToPoint(context, 100,200, 300,200, 100);

CGContextStrokePath(context);

*/

/*

绘制贝兹曲线

//贝兹曲线是通过移动一个起始点,然后通过两个控制点,还有一个中止点,调用CGContextAddCurveToPoint() 函数绘制

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGContextMoveToPoint(context, 10, 10);

CGContextAddCurveToPoint(context, 0, 50, 300, 250, 300, 400);

CGContextStrokePath(context);

*/

/*绘制二次贝兹曲线

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGContextMoveToPoint(context, 10, 200);

CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);

CGContextStrokePath(context);

*/

/*绘制虚线

CGContextSetLineWidth(context, 5.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGFloat dashArray[] = {2,6,4,2};

CGContextSetLineDash(context, 3, dashArray, 4);//跳过3个再画虚线,所以刚开始有6-(3-2)=5个虚点

CGContextMoveToPoint(context, 10, 200);

CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);

CGContextStrokePath(context);

*/

/*绘制图片

NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];

UIImage* myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath];

//[myImageObj drawAtPoint:CGPointMake(0, 0)];

[myImageObj drawInRect:CGRectMake(0, 0, 320, 480)];

NSString *s = @"我的小狗";

[s drawAtPoint:CGPointMake(100, 0) withFont:[UIFont systemFontOfSize:34.0]];

*/

/*

NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];

UIImage *img = [UIImage imageWithContentsOfFile:path];

CGImageRef image = img.CGImage;

CGContextSaveGState(context);

CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);

CGContextDrawImage(context, touchRect, image);

CGContextRestoreGState(context);

*/

/*NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];

UIImage *img = [UIImage imageWithContentsOfFile:path];

CGImageRef image = img.CGImage;

CGContextSaveGState(context);

CGContextRotateCTM(context, M_PI);

CGContextTranslateCTM(context, -img.size.width, -img.size.height);

CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);

CGContextDrawImage(context, touchRect, image);

CGContextRestoreGState(context);*/

/*

NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];

UIImage *img = [UIImage imageWithContentsOfFile:path];

CGImageRef image = img.CGImage;

CGContextSaveGState(context);

CGAffineTransform myAffine = CGAffineTransformMakeRotation(M_PI);

myAffine = CGAffineTransformTranslate(myAffine, -img.size.width, -img.size.height);

CGContextConcatCTM(context, myAffine);

CGContextRotateCTM(context, M_PI);

CGContextTranslateCTM(context, -img.size.width, -img.size.height);

CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);

CGContextDrawImage(context, touchRect, image);

CGContextRestoreGState(context);

*/

}

拷贝别人的drawRect绘图分类用途、用法很全。的更多相关文章

  1. WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选)

    原文:WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选) 前台代码 <DataGrid.Columns> <DataGridCheckB ...

  2. javascript的canvas绘图的基本用法

    <canvas>是HTML里面非常强大的元素,利用它结合js可以实现很多动画效果,大大增强交互性.下面,我想用图文并茂的方式阐述一下canvas的绘图机制的基础内容,话不多说,先上代码: ...

  3. Linux 下 Shell 命令的分类及用法

    当你打算真正操纵好你的 Linux 系统,没有什么能比命令行界面更让你做到这一点.为了成为一个 Linux 高手,你必须能够理解 Shell命令的不同类型,并且会在终端下正确的使用它们. 在 Linu ...

  4. C语言——常用标准输入输出函数 scanf(), printf(), gets(), puts(), getchar(), putchar(); 字符串拷贝函数 strcpy(), strncpy(), strchr(), strstr()函数用法特点

    1 首先介绍几个常用到的转义符 (1)     换行符“\n”, ASCII值为10: (2)     回车符“\r”, ASCII值为13: (3)     水平制表符“\t”, ASCII值为 9 ...

  5. MVC Controller return 格式分类及用法

    概述 所看到的Action都是return View();我们可以看作这个返回值用于解析一个aspx文件.而它的返回类型是ActionResult如 public ActionResult Index ...

  6. Java中修饰符的分类及用法

    访问权限修饰符: public 修饰class,方法,变量: 所修饰类的名字必须与文件名相同,文件中最多能有一个pulic修饰的类. private class不可用,方法,变量可以用: 只限于本类成 ...

  7. Font Awesome字体图标的 用法, 很简单

    http://fontawesome.dashgame.com/ 上面是 官网,  可下载,也可以CDN. 1...  加载 2...  用法

  8. qt5信息提示框QMessageBox用法(很全)

    information QMessageBox::information(NULL, "Title", "Content", QMessageBox::Yes ...

  9. C++ 拷贝构造函数与赋值函数的区别(很严谨和全面)

    这里我们用类String 来介绍这两个函数: 拷贝构造函数是一种特殊构造函数,具有单个形参,该形参(常用const修饰)是对该类类型的引用.当定义一个新对象并用一个同类型的对象对它进行初始化时,将显式 ...

随机推荐

  1. 数独高阶技巧入门之七——AIC & Nice Loop

    AIC(交替推理链,Alternate Inference Chain) 在简单异数链一文中我们介绍过XY-Chain技法,AIC可以看作是XY-Chain的扩展.有别于XY-Chain仅局限于双值格 ...

  2. 十九、Node.js-非阻塞IO、异步以及 '事件驱动EventEmitter'解决异步

    1.Nodejs 的单线程 非阻塞 I/O 事件驱动 在 Java.PHP 或者.net 等服务器端语言中,会为每一个客户端连接创建一个新的线程而每个线程需要耗费大约 2MB 内存.也就是说,理论上, ...

  3. 关于C# 向TIM或者QQ自动发送中文消息【微信也是可用的】 附测试GIF中微信可用的 全新修订

    在上一篇文章的代码 对于微信已失效 重新更新一边 效果图: 源代码 using System; using System.Runtime.InteropServices; using System.T ...

  4. value_counts()

    Serise类型: Series.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True) 功 ...

  5. jQuery实现ie浏览器兼容placeholder效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. “全栈2019”Java第七十二章:静态内部类访问外部类成员

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  7. redis 限制接口访问频率

    代码: <?php /** * */ class myRedis { private static $redis = null; /** * @return null|Redis */ publ ...

  8. linux设置ip别名

    修改文件 # vi /etc/hosts 添加地址和别名 192.168.222.126 s1 ##前面是机器ip,后面是别名 测试 [root@bogon /]# ping s1 PING s1 ( ...

  9. myeclipse部署项目到tomcat-custom_location 方式

    在想要部署的路径下:1.新建一个在tomcat--->server.xml文件夹下设置的文件名 2.在新建的文件夹下新建一个  ROOT文件夹, 3.在myeclipse里面吧项目部署到 ROO ...

  10. java 数字转 字符串 互相转换

    各种数字类型转换成字符串型:   String s = String.valueOf( value); // 其中 value 为任意一种数字类型.   字符串型转换成各种数字类型:   String ...