//常用属性

/*

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     // 斜角衔接

*/

 1 -(void)drawRect:(CGRect)rect{
 2
 3     //设置路径线条颜色
 4     [[UIColor redColor] setStroke];
 5
 6     //绘制直线
 7     UIBezierPath *path1 = [UIBezierPath bezierPath];
 8     [path1 moveToPoint:CGPointMake(30, 100)];
 9     [path1 addLineToPoint:CGPointMake(300, 100)];
10     CGFloat dash[] = {3.0, 3.0};
11     //这里可以设置线条为虚线,前一个数字表示虚线长度,后者表示虚线间隔。
12     //[path1 setLineDash:dash count:2 phase:0];
13     [path1 stroke];
14
15     //绘制折线
16     UIBezierPath *path = [UIBezierPath bezierPath];
17     [path moveToPoint:CGPointMake(30, 120)];
18     [path addLineToPoint:CGPointMake(100, 120)];
19     [path addLineToPoint:CGPointMake(60, 170)];
20     //[path closePath];当端点>=2时,可以闭合路径.
21     [path stroke];
22
23     //二次贝塞尔曲线
24     UIBezierPath *path2 = [UIBezierPath bezierPath];
25     [path2 moveToPoint:CGPointMake(150, 150)];
26     [path2 addQuadCurveToPoint:CGPointMake(300, 150) controlPoint:CGPointMake(200, 80)];
27     [path2 stroke];
28
29     //三次贝塞尔曲线方法
30     UIBezierPath *path3 = [UIBezierPath bezierPath];
31     [path3 moveToPoint:CGPointMake(30, 200)];
32     [path3 addCurveToPoint:CGPointMake(200, 250) controlPoint1:CGPointMake(80, 300) controlPoint2:CGPointMake(150, 150)];
33     [path3 stroke];
34
35     //绘制矩形
36     UIBezierPath *path4 = [UIBezierPath bezierPathWithRect:CGRectMake(250, 200, 100, 100)];
37     [path4 stroke];
38
39     //绘制椭圆,如果长宽相等,则绘制的就是圆形
40     UIBezierPath *path5 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(150, 300, 100, 60)];
41     [path5 stroke];
42
43     //绘制带圆角的矩形
44     UIBezierPath *path6 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(30, 250, 100, 100) cornerRadius:10];
45     [path6 stroke];
46
47     //绘制矩形,并可指定某个角为圆角
48     //    UIRectCornerTopLeft   左上
49     //    UIRectCornerTopRight  右上
50     //    UIRectCornerBottomLeft  左下
51     //    UIRectCornerBottomRight  右下
52     UIBezierPath *path7 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(30, 400, 100, 100) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(40, 40)];
53     [path7 stroke];
54
55     //绘制圆弧
56     //ArcCenter圆点  radius半径  startAngle开始弧度  endAngle结束弧度 clockwise是否顺时针
57     UIBezierPath *path8 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(200, 450) radius:50 startAngle:0 endAngle:M_PI_2*3 clockwise:YES];
58     [path8 stroke];
59
60     //绘制扇形
61     UIBezierPath *path9 = [UIBezierPath bezierPath];
62     [path9 moveToPoint:CGPointMake(100, 520)];
63     [path9 addArcWithCenter:CGPointMake(100, 520) radius:100 startAngle:0 endAngle:M_PI_2 clockwise:YES];
64     [[UIColor redColor] setFill];//设置填充颜色
65     [path9 closePath];//关闭路径
66     [path9 fill];//设置填充
67     [path9 stroke];
68 }

若不在

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

其它图形的绘制类似

 1 UIBezierPath *path = [UIBezierPath bezierPath];
 2     [path moveToPoint:CGPointMake(30, 100)];
 3     [path addLineToPoint:CGPointMake(100, 100)];
 4
 5     //这里是用了CAShapeLayer,个人习惯在layer里设置线宽、断点样式、连接点样式
 6 //    path.lineWidth = 3;
 7 //    path.lineCapStyle = kCGLineCapSquare;
 8 //    path.lineJoinStyle = kCGLineJoinMiter;
 9
10     CAShapeLayer *layer = [CAShapeLayer layer];
11     layer.path = path.CGPath;
12     layer.lineWidth = 3;
13     layer.lineCap = kCALineCapSquare;
14     layer.lineJoin = kCALineJoinRound;
15     //填充颜色
16     layer.fillColor = [UIColor clearColor].CGColor;
17     //线条填充颜色
18     layer.strokeColor = [UIColor redColor].CGColor;
19     [self.view.layer addSublayer:layer];

效果图:

转载于:https://www.cnblogs.com/lfyDragon/p/8761021.html

贝塞尔曲线UIBezierPath简单使用相关推荐

  1. ios 贝塞尔曲线 颜色填充_iOS,贝塞尔曲线(UIBezierPath)

    UIBezierPath简介 使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装, UIBezierPath对象是C ...

  2. iOS开发 贝塞尔曲线UIBezierPath

    2019独角兽企业重金招聘Python工程师标准>>> UIBezierPath基础 UIBezierPath对象是CGPathRef数据类型的封装.每一个直线段或者曲线段的结束的地 ...

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

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

  4. 贝塞尔曲线原理(简单阐述)

    贝塞尔曲线原理(简单阐述) https://www.cnblogs.com/hnfxs/p/3148483.html 原理和简单推导(以三阶为例): 设P0.P02.P2是一条抛物线上顺序三个不同的点 ...

  5. HTML5画布Canvas线段、矩形、弧形及贝塞尔曲线等简单图形绘制

    tip:有问题或者需要大厂内推的+我脉脉哦:丛培森 ٩( 'ω' )و HTML5中最有意思的就是这个canvas了 通过它我们可以画自己想要的图形 它也是十分重要的技术 应用于游戏.图表等等 或者绘 ...

  6. ios 贝塞尔曲线 颜色填充_iOS贝塞尔曲线(UIBezierPath)的基本使用方法

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

  7. ios 贝塞尔曲线 颜色填充_iOS UIBezierPath贝赛尔曲线详解

    UIBezierPath是在画图,定制动画轨迹中都有应用. UIBezierPath主要用来绘制矢量图形,它是基于Core Graphics对CGPathRef数据类型和path绘图属性的一个封装,所 ...

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

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

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

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

最新文章

  1. 360不用卸,照样上你QQ
  2. ssm使用全注解实现增删改查案例——DeptServiceImpl
  3. 1042: 筛法求素数
  4. 【BZOJ1044】【tyvj3511】【codevs1870】木棍分割,二分答案+滚动数组+前缀和DP
  5. 带中文字库的12864LCD显示程序
  6. Linux系统多网卡环境下的路由配置
  7. 散列函数之双重散列算法解决冲突问题
  8. 灰度重采样的方法分为_遥感导论-期末试卷及答案
  9. [Luogu4173/BZOJ4259] 残缺的字符串
  10. 常见物理量的量纲在OpenFOAM中的表示
  11. 2N个数排成一行(每个数有2个), 2个1之间有1个数,2个2 之间有2个数,...2个N之间有N个数... 例312132
  12. java求矩阵的逆矩阵_Java逆矩阵计算
  13. 13.tornado操作之增加用户喜欢的图片展示页+同时展示用户上传的所有图片增加展示图片有多少用户喜欢的功能
  14. Java 的字节与字符输入/输出流的类整理——zyx笔记
  15. 利用requests库和Xpath爬取猫眼电影榜单【Python】
  16. PLM系统能给企业带来什么
  17. 《绝地求生》玩家排名预测
  18. VScode Extension activation failed的解决方法
  19. 玩VR眼镜对眼睛有影响和危害吗?2018VR眼镜排行榜,什么VR眼镜好推荐,哪个VR眼镜好?
  20. Gym 102055L Ultra Weak Goldbach's Conjecture (素数密度+打表/哥德巴赫猜想)

热门文章

  1. inside the C++ Object model总结
  2. 社交网站 分享 +button
  3. HBase之MVCC
  4. spark基础之checkpoint机制
  5. (07)FPGA基本组成单元
  6. (31)FPGA面试题系统最高速度计算方法
  7. Verilog实现3分频实例
  8. python字符串说法错误的是_【单选题】关于Python字符串的表示方法,下列说法错误的是: A. 字符串是字符的序列表示,只能由...
  9. 12025.petalinux 之phy调试ping(三)
  10. leecode-3无重复字符串的最长子字符串C版-滑动窗口