iOS UIBezierPath曲线 贝塞尔曲线 二

运行如下:

未调用closePath
调用closePath

2、画矩形

UIColor*color=[UIColor redColor];

[color set];//设置线条颜色

UIBezierPath*bezierPath=[UIBezierPath bezierPathWithRect:CGRectMake(20,20,100,50)];

bezierPath.lineWidth=3.0;

bezierPath.lineCapStyle=kCGLineCapSquare;//线条拐角

bezierPath.lineJoinStyle=kCGLineJoinBevel;//终点处理

[bezierPath stroke];

运行如下:

3、画椭圆

//UIColor*stroke=[UIColor redColor];//设置红色画笔线

//[stroke set];//填充颜色

//UIBezierPath*bezierPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(60,60,50,40)];

//[bezierPath fill];

//[bezierPath stroke];//fill和stroke的区别:fill是用线连接并填充stroke就是用线连接不填充

运行如下:

fill


stroke

4、画弧线

UIColor*color=[UIColor redColor];

[color set];//设置线条颜色

UIBezierPath*bezierPath=[UIBezierPath bezierPathWithArcCenter:CGPointMake(100,100) radius:40 startAngle:M_PI_4 endAngle:M_PI clockwise:YES];

bezierPath.lineWidth=5.0;

bezierPath.lineCapStyle=kCGLineCapRound;

bezierPath.lineJoinStyle=kCGLineJoinRound;

[bezierPath stroke];

运行如下:

5、画弧线---有一个控制点,如下图:

一个控制点

UIColor*color=[UIColor redColor];

[color set];

UIBezierPath*bezierPath=[UIBezierPath bezierPath];

bezierPath.lineWidth=3.0;

bezierPath.lineCapStyle=kCGLineCapRound;//线拐角

bezierPath.lineJoinStyle=kCGLineJoinRound;//接点处理

[bezierPath moveToPoint:CGPointMake(10,100)];

[bezierPath addQuadCurveToPoint:CGPointMake(150,100)controlPoint:CGPointMake(85,10)];

[bezierPath stroke];

运行如下:

一个控制点

6、画弧线-两个控制点,如下图:

两个控制点

UIColor*color=[UIColor redColor];

[color set];

UIBezierPath*bezierPath=[UIBezierPath bezierPath];

bezierPath.lineWidth=3.0;

bezierPath.lineCapStyle=kCGLineCapRound;//线条拐角

bezierPath.lineJoinStyle=kCGLineJoinRound;//终点处理

[bezierPath moveToPoint:CGPointMake(10,100)];

[bezierPath addCurveToPoint:CGPointMake(200,100)controlPoint1:CGPointMake(80,20)controlPoint2:CGPointMake(150,150)];

[bezierPath stroke];

运行如下:

两个控制点
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容