文章目录
  1. 1. UIBezierPath使用

UIBezierPath使用

Ios基础语法

贝塞尔弧线介绍:

1,UIBerzierPath类可以创建矢量路径,此类为Core Grapice框架关于path的一个封装

2,UIBezierPath对象是CGPathRef数据类型封装,一个UIBezierPath对象定义一个完整的路径包括一个或者多个subpaths,包括直线和曲线。

使用方法:
1,创建一个path对象
2,使用方法moveToPoint:设置初始线段的起点
3,添加line或者curve定义一个或者多个subpaths
4,添加UIBezierPath对象绘图的属性

常用实例方法:
//根据一个矩形画曲线

  • (UIBezierPath *)bezierPathWithRect:(CGRect)rect

 

//根据矩形框的内切圆画曲线

+(UIBezierPath *)bezierPathWithOvalInRect:(CGRect)rect

//根据矩形画带圆角的曲线

  • (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius

//在矩形中,可以针对四角中的某个角加圆角

  • (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii

参数:

corners:枚举值,可以选择某个角

cornerRadii:圆角的大小

//以某个中心点画弧线

  • (UIBezierPath *)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
    参数:

center:弧线中心点的坐标

radius:弧线所在圆的半径

startAngle:弧线开始的角度值

endAngle:弧线结束的角度值

clockwise:是否顺时针画弧线

 

//画二元曲线,一般和moveToPoint配合使用

  • (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint

参数:

endPoint:曲线的终点

controlPoint:画曲线的基准点

 

//以三个点画一段曲线,一般和moveToPoint配合使用

  • (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2

参数:

endPoint:曲线的终点

controlPoint1:画曲线的第一个基准点

controlPoint2:画曲线的第二个基准点 

//设置初始线段的起点

  • (void)moveToPoint:(CGPoint)point

简单代码如下:
    UIBezierPath *path=[UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0, 0)];
    [path addLineToPoint:CGPointMake(60, 60)];
    [path addLineToPoint:CGPointMake(20, 20)];
    [path closePath];//关闭path,这个方法会自动连接最后点和起始点
画圆弧
    UIBezierPath *path=[UIBezierPath bezierPath];
    [path addArcWithCenter:CGPointMake(100, 100) radius:60 startAngle:0 endAngle:360 clockwise:YES];
立方和二次贝塞尔曲线

文章目录
  1. 1. UIBezierPath使用