//常用属性

/*

1.CGPath: 将UIBezierPath类转换成CGPath

2.currentPoint: 当前path的位置,可以理解为path的终点

3.lineWidth: 线条宽度

4.lineCapStyle: 端点样式

5.lineJoinStyle: 连接类型

6.flatness: 绘线的精细程度,默认为0.6,数值越大,需要处理的时间越长

7.usesEvenOddFillRule: 判断奇偶数组的规则绘制图像,图形复杂时填充颜色的一种规则。类似棋盘

8.miterLimit: 最大斜接长度(只有在使用kCGLineJoinMiter是才有效,最大限制为10), 边角的角度越小,斜接长度就会越大,为了避免斜接长度过长,使用lineLimit属性限制,如果斜接长度超过miterLimit,边角就会以KCALineJoinBevel类型来显示

9.- setLineDash:count:phase:为path绘制虚线,dash数组存放各段虚线的长度,count是数组元素数量,phase是起始位置

*/

lineCapStyle     // 端点类型

/*

kCGLineCapButt,     // 无端点

kCGLineCapRound,    // 圆形端点

kCGLineCapSquare    // 方形端点(样式上和kCGLineCapButt是一样的,但是比kCGLineCapButt长一点)

*/

lineJoinStyle     // 交叉点的类型

/*

kCGLineJoinMiter,    // 尖角衔接

kCGLineJoinRound,    // 圆角衔接

kCGLineJoinBevel     // 斜角衔接

*/

 -(void)drawRect:(CGRect)rect{

     //设置路径线条颜色
[[UIColor redColor] setStroke]; //绘制直线
UIBezierPath *path1 = [UIBezierPath bezierPath];
[path1 moveToPoint:CGPointMake(, )];
[path1 addLineToPoint:CGPointMake(, )];
CGFloat dash[] = {3.0, 3.0};
//这里可以设置线条为虚线,前一个数字表示虚线长度,后者表示虚线间隔。
//[path1 setLineDash:dash count:2 phase:0];
[path1 stroke]; //绘制折线
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(, )];
[path addLineToPoint:CGPointMake(, )];
[path addLineToPoint:CGPointMake(, )];
//[path closePath];当端点>=2时,可以闭合路径.
[path stroke]; //二次贝塞尔曲线
UIBezierPath *path2 = [UIBezierPath bezierPath];
[path2 moveToPoint:CGPointMake(, )];
[path2 addQuadCurveToPoint:CGPointMake(, ) controlPoint:CGPointMake(, )];
[path2 stroke]; //三次贝塞尔曲线方法
UIBezierPath *path3 = [UIBezierPath bezierPath];
[path3 moveToPoint:CGPointMake(, )];
[path3 addCurveToPoint:CGPointMake(, ) controlPoint1:CGPointMake(, ) controlPoint2:CGPointMake(, )];
[path3 stroke]; //绘制矩形
UIBezierPath *path4 = [UIBezierPath bezierPathWithRect:CGRectMake(, , , )];
[path4 stroke]; //绘制椭圆,如果长宽相等,则绘制的就是圆形
UIBezierPath *path5 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )];
[path5 stroke]; //绘制带圆角的矩形
UIBezierPath *path6 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(, , , ) cornerRadius:];
[path6 stroke]; //绘制矩形,并可指定某个角为圆角
// UIRectCornerTopLeft 左上
// UIRectCornerTopRight 右上
// UIRectCornerBottomLeft 左下
// UIRectCornerBottomRight 右下
UIBezierPath *path7 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(, , , ) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(, )];
[path7 stroke]; //绘制圆弧
//ArcCenter圆点 radius半径 startAngle开始弧度 endAngle结束弧度 clockwise是否顺时针
UIBezierPath *path8 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(, ) radius: startAngle: endAngle:M_PI_2* clockwise:YES];
[path8 stroke]; //绘制扇形
UIBezierPath *path9 = [UIBezierPath bezierPath];
[path9 moveToPoint:CGPointMake(, )];
[path9 addArcWithCenter:CGPointMake(, ) radius: startAngle: endAngle:M_PI_2 clockwise:YES];
[[UIColor redColor] setFill];//设置填充颜色
[path9 closePath];//关闭路径
[path9 fill];//设置填充
[path9 stroke];
}

若不在

-(void)drawRect:(CGRect)rect方法中使用贝塞尔曲线,直接在viewDidLoad中使用,则如下:

其它图形的绘制类似

 UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(, )];
[path addLineToPoint:CGPointMake(, )]; //这里是用了CAShapeLayer,个人习惯在layer里设置线宽、断点样式、连接点样式
// path.lineWidth = 3;
// path.lineCapStyle = kCGLineCapSquare;
// path.lineJoinStyle = kCGLineJoinMiter; CAShapeLayer *layer = [CAShapeLayer layer];
layer.path = path.CGPath;
layer.lineWidth = ;
layer.lineCap = kCALineCapSquare;
layer.lineJoin = kCALineJoinRound;
//填充颜色
layer.fillColor = [UIColor clearColor].CGColor;
//线条填充颜色
layer.strokeColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:layer];

效果图:

贝塞尔曲线UIBezierPath简单使用的更多相关文章

  1. iOS开发 贝塞尔曲线UIBezierPath(2)

    使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...

  2. iOS开发 贝塞尔曲线UIBezierPath(后记)

    使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...

  3. iOS开发 贝塞尔曲线UIBezierPath

    最近项目中需要用到用贝塞尔曲线去绘制路径 ,然后往路径里面填充图片,找到这篇文章挺好,记录下来 自己学习! 转至 http://blog.csdn.net/guo_hongjun1611/articl ...

  4. cocos2d-x 贝塞尔曲线的简单运用(CCBezierTo,CCBezierBy)

    原文链接:http://blog.csdn.net/we000636/article/details/8616355 一.贝赛尔曲线简单介绍 贝塞尔曲线是应用于二维图形应用程序的数学曲线.曲线的定义有 ...

  5. 关于cubic-bezier 贝塞尔曲线的简单了解

    在animation和transition两个属性中,cubic-bezier是控制变化的速度曲线,主要是生成速度曲线的函数 规定用法是: cubic-bezier(<x1>,<y1 ...

  6. iOS贝塞尔曲线(UIBezierPath)的基本使用方法

    简介 UIBezierPath是对Core Graphics框架的一个封装,使用UIBezierPath类我们可以画出圆形(弧线)或者多边形(比如:矩形)等形状,所以在画复杂图形的时候会经常用到. 分 ...

  7. 通过UIBezierPath贝塞尔曲线画圆形、椭圆、矩形

    /**创建椭圆形的贝塞尔曲线*/ UIBezierPath *_ovalPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; ...

  8. iOS开发 贝塞尔曲线

    iOS开发 贝塞尔曲线UIBezierPath - 陌云 时间 2014-03-14 11:04:00  博客园-所有随笔区 原文  http://www.cnblogs.com/moyunmo/p/ ...

  9. 基于CAShapeLayer和贝塞尔曲线的圆形进度条动画

    通过CAShapeLayer和贝塞尔曲线搭配的方法,创建的简单的圆形进度条的教程先简单的介绍下CAShapeLayer1,CAShapeLayer继承自CALayer,可使用CALayer的所有属性2 ...

随机推荐

  1. spring boot 上传文件

    spring.servlet.multipart.max-file-size=23KBspring.servlet.multipart.maxRequestSize=23KB <form act ...

  2. python 中range函数的用法

    一. range(start,end,step) 二.代码 [code1] for i in range(1,10,2): print("i=",i) [result1] i= 1 ...

  3. 【WebAPI No.5】Core WebAPI中的自定义格式化

    介绍 Web API为JSON和XML提供媒体类型格式化程序.框架默认将这些格式化程序插入管道中.客户端可以在HTTP请求的Accept标头中请求JSON或XML. 格式化数据这个东西,其实没有什么最 ...

  4. servlet 请求乱码解决

  5. Hadoop RPC源码分析

    Hadoop RPC源码分析 上一篇文章http://www.cnblogs.com/dycg/p/rpc.html 讲了Hadoop RPC的使用方法,这一次我们从demo中一层层进行分析. RPC ...

  6. C# 动态生成类 枚举等

    private void GenerateCode() { /*注意,先导入下面的命名空间 using System.CodeDom using System.CodeDom.Compiler; us ...

  7. 从零开始学 Web 之 HTML5(一)HTML5概述,语义化标签

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  8. OS开发(2):自定义tabbar | 导航条 | 突显中间按钮

    tabbar是放在APP底部的控件,也叫navigationbar或导航条.常见的APP都使用tabbar来进行功能分类的管理,比如微信.QQ等等. 需求是这样的,需要一个特殊一点的tabbar,要求 ...

  9. ida 调试 android fork

    在使用ida 调试android native代码时经常会碰见fork子进程的情况出现,而运行一个 android_server只能对一个进程进行调试或者attach,而ida 默认端口是23946, ...

  10. 看懂「www.google.com」背后的逻辑

    在前两篇文章中,我们完整的描述了计算机网络 OSI 五层模型的相关内容.那么,本篇将会从一个实践案例开始,带你从整体上重新认识我们的计算机网络. 我们以访问 Google 为例,当我们在浏览器地址栏中 ...