iOS 画贝塞尔曲线代码

#import "ViewController.h"


#define pi 3.14159265359

#define   DEGREES_TO_RADIANS(degrees)  ((pi * degrees)/ 180)


@interface ViewController ()


@property(nonatomic, strong) CAShapeLayer *shapeLayer;


@end


    self.shapeLayer = [CAShapeLayer layer];

    _shapeLayer.frame = CGRectMake(0, 0, 200, 200);

    _shapeLayer.position = self.view.center;

    _shapeLayer.fillColor = [UIColor clearColor].CGColor;

    

    _shapeLayer.lineWidth = 1.0f;

    _shapeLayer.strokeColor = [UIColor redColor].CGColor;

    

//    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];

    

//    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];

    

    

//    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150)

//                                                         radius:75

//                                                     startAngle:0

//                                                       endAngle:DEGREES_TO_RADIANS(135)

//                                                      clockwise:YES];

    

//    //绘制二次贝塞尔曲线

//    UIBezierPath *circlePath = [UIBezierPath bezierPath];

    [circlePath moveToPoint:CGPointMake(20, 100)];

//    [circlePath moveToPoint:CGPointMake(0, 100)];

//    [circlePath addQuadCurveToPoint:CGPointMake(200, 100) controlPoint:CGPointMake(100, 0)];

    

    

    //绘制三次贝塞尔曲线

    //绘制二次贝塞尔曲线

    UIBezierPath *circlePath = [UIBezierPath bezierPath];

//    //    [circlePath moveToPoint:CGPointMake(20, 100)];

//    [circlePath moveToPoint:CGPointMake(0, 100)];

//    [circlePath addQuadCurveToPoint:CGPointMake(200, 100) controlPoint:CGPointMake(100, 0)];

    

    [circlePath moveToPoint:CGPointMake(20, 50)];

    

    [circlePath addCurveToPoint:CGPointMake(200, 50) controlPoint1:CGPointMake(110, 0) controlPoint2:CGPointMake(110, 100)];

    

    

    _shapeLayer.path = circlePath.CGPath;

    

    

    _shapeLayer.strokeStart = 0;

    _shapeLayer.strokeEnd = 1.0;

    

    [self.view.layer addSublayer:_shapeLayer];


    //绘制贝兹曲线

    //贝兹曲线是通过移动一个起始点,然后通过两个控制点,还有一个中止点,调用CGContextAddCurveToPoint() 函数绘制

    CGContextSetLineWidth(context, 2.0);

    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

    CGContextMoveToPoint(context, 10, 10);

    CGContextAddCurveToPoint(context, 20050100400300400);

    CGContextStrokePath(context);

    

    

    //绘制连续的曲线

    CGContextSetLineWidth(context, 5.0);

    CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);

    CGContextMoveToPoint(context, 230, 150);//开始画线, xy 为开始点的坐标

    CGContextAddCurveToPoint(context, 310100300200220220);//画三次点曲线

    CGContextAddCurveToPoint(context, 290140280180240190);//画三次点曲线

    

    CGContextStrokePath(context);//开始画线


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值