贝塞尔曲线UIBezierPath简单使用
//常用属性
/*
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简单使用的更多相关文章
- iOS开发 贝塞尔曲线UIBezierPath(2)
使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...
- iOS开发 贝塞尔曲线UIBezierPath(后记)
使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...
- iOS开发 贝塞尔曲线UIBezierPath
最近项目中需要用到用贝塞尔曲线去绘制路径 ,然后往路径里面填充图片,找到这篇文章挺好,记录下来 自己学习! 转至 http://blog.csdn.net/guo_hongjun1611/articl ...
- cocos2d-x 贝塞尔曲线的简单运用(CCBezierTo,CCBezierBy)
原文链接:http://blog.csdn.net/we000636/article/details/8616355 一.贝赛尔曲线简单介绍 贝塞尔曲线是应用于二维图形应用程序的数学曲线.曲线的定义有 ...
- 关于cubic-bezier 贝塞尔曲线的简单了解
在animation和transition两个属性中,cubic-bezier是控制变化的速度曲线,主要是生成速度曲线的函数 规定用法是: cubic-bezier(<x1>,<y1 ...
- iOS贝塞尔曲线(UIBezierPath)的基本使用方法
简介 UIBezierPath是对Core Graphics框架的一个封装,使用UIBezierPath类我们可以画出圆形(弧线)或者多边形(比如:矩形)等形状,所以在画复杂图形的时候会经常用到. 分 ...
- 通过UIBezierPath贝塞尔曲线画圆形、椭圆、矩形
/**创建椭圆形的贝塞尔曲线*/ UIBezierPath *_ovalPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; ...
- iOS开发 贝塞尔曲线
iOS开发 贝塞尔曲线UIBezierPath - 陌云 时间 2014-03-14 11:04:00 博客园-所有随笔区 原文 http://www.cnblogs.com/moyunmo/p/ ...
- 基于CAShapeLayer和贝塞尔曲线的圆形进度条动画
通过CAShapeLayer和贝塞尔曲线搭配的方法,创建的简单的圆形进度条的教程先简单的介绍下CAShapeLayer1,CAShapeLayer继承自CALayer,可使用CALayer的所有属性2 ...
随机推荐
- Data - Spark简介
Spark简介 Spark是基于内存计算的大数据并行计算框架,可用于构建大型的.低延迟的数据分析应用程序. HomePage:http://spark.apache.org/ GitHub:https ...
- 07-部署Flanneld网络
部署Flanneld网络 Flanneld:用于解决容器之间网络互通,这里我们要配置TLS认证. Docker1.12.5:docker的安装很简单,这里也不说了. 配置Flanneld 这里我们使用 ...
- 终于等到你!阿里正式向 Apache Flink 贡献 Blink 源码
摘要: 如同我们去年12月在 Flink Forward China 峰会所约,阿里巴巴内部 Flink 版本 Blink 将于 2019 年 1 月底正式开源.今天,我们终于等到了这一刻. 阿里妹导 ...
- vue 父子组件之间传参
父组件中有子组件 msg 为父组件向子组件传的内容, 子组件向父组件传参数 子组件:this.$emit("shownumber",[this.num]);//this.$emi ...
- 4 spring 创建对象的三种方式
方式1. 通过构造方法创建 1.1 无参构造创建:默认情况. 1.2 有参构造创建:需要明确配置 1.2.1 需要在类中提供有参构造方法 1.2.2 在 ...
- SQL Server性能优化(11)非聚集索引的覆盖索引存储结构
一,非聚集索引的include 非聚集索引的Include属性可以让非聚集索引包含其他列.如 CREATE NONCLUSTERED INDEX [NonIxUser] ON [dbo].[Users ...
- kafka的迁移干货
随着业务的发展, 服务器所在网段/机群不允许kafka继续保留在那, 需要移动到先机器上. 哎呀上面是废话,总的说就是: 2台老kafka不要了,数据要迁移到新的2台kafka上面.要求数据不丢失 通 ...
- vmware workstation 提示程序包可能有错,错误代码 29141 & 提示不可恢复错误: (vcpu-0)
问题一:提示程序包可能有错,错误代码 29141 换了n个版本(vmware workstation 10,11, 12),下载了n次,都提示该错误(29141),明明程序包没错啊, 一开始还怀疑是我 ...
- 使用webpack将es6 es7转换成es2015
第一步:安装模块化包 cnpm install --save-dev babel-core babel-loader babel-preset-es2015 babel-preset-react 第二 ...
- C++中的字符串可以这样换行写
运行结果: