iOS BezierPath 贝塞尔曲线的绘制

//绘制矩形
- (void)drawSequl
{
    UIColor * color =[UIColor redColor];
    //设置画笔颜色
    [color setFill];

    UIRectFill(CGRectMake(10, 10, 100, 100));
}


//绘制自定义矩形
- (void)drawDiySqul
{
    //设置线条颜色
    UIColor * color =[UIColor colorWithRed:0 green:0 blue:0.7 alpha:1];
    [color set];

    UIBezierPath * path = [UIBezierPath bezierPathWithRect:CGRectMake(10, 10, 100, 100)];
    path.lineWidth = 2;
    path.lineCapStyle = kCGLineCapRound;  //设置线条的拐角
    path.lineJoinStyle = kCGLineJoinRound;  //终点处理

    [path stroke];
}

//画圆
- (void)drawCircle
{
    [[UIColor redColor] set];
//    UIBezierPath * path =[UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 400, 400) cornerRadius:200];

    //画椭圆只要把高或者宽 改一下即可
    UIBezierPath * path =[UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, 200, 200)];

    path.lineWidth =8;

    [path stroke];
}

//多边形
- (void)drawDiyGraph
{
    //设置画笔颜色
    [[UIColor orangeColor] set];

    UIBezierPath * path =[UIBezierPath bezierPath];
    path.lineWidth = 4;
    path.lineCapStyle = kCGLineCapRound;
    path.lineJoinStyle = kCGLineJoinRound;

    //设置起点
    [path moveToPoint:CGPointMake(10, 10)];

    //绘制线条
    [path addLineToPoint:CGPointMake(60, 10)];
    [path addLineToPoint:CGPointMake(60, 20)];
    [path addLineToPoint:CGPointMake(50, 70)];
    [path addLineToPoint:CGPointMake(30, 120)];
    [path addLineToPoint:CGPointMake(20, 200)];

    //最后一条线封闭图形
    [path closePath];

    //根据坐标点连线
    [path stroke];

    //填充
    [path fill];

}

//绘制不规则图形
- (void)drawIrregularity
{
    //设置画笔颜色
    [[UIColor whiteColor] set];

    /*第一个参数圆点
      第二个参数 半径
      第三个参数 初始角度  (弧度使用顺时针脚底,0弧度指向右边,pi/2指向下方,pi指向左边,-pi/2指向上方)
      第四个参数 结束角度
     */
    UIBezierPath * path =[UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:90 startAngle:0 endAngle:3.14/2*3 clockwise:YES];
    path.lineWidth = 8;

    [path stroke];
}


//绘制贝塞尔曲线
- (void)drawBersizer
{
    //设置画笔颜色
    [[UIColor whiteColor]set];

    UIBezierPath * path = [UIBezierPath bezierPath];

    path.lineWidth = 4;

    [path moveToPoint:CGPointMake(10, 210)];

    [path addQuadCurveToPoint:CGPointMake(310, 210) controlPoint:CGPointMake(100, 50)];

    [path stroke];

}

//贝塞尔波浪线
- (void)drawBolang
{
    //设置画笔颜色
    [[UIColor whiteColor]set];

    //
    UIBezierPath * path = [UIBezierPath bezierPath];
    path.lineWidth =6;


    [path moveToPoint:CGPointMake(10, 310)];
    [path addCurveToPoint:CGPointMake(370, 310) controlPoint1:CGPointMake(130, 210) controlPoint2:CGPointMake(250, 410)];

    [path stroke];
}

//波浪 (多个拐弯)
- (void)drawLLLL
{
    [[UIColor whiteColor]set];


    UIBezierPath * path = [UIBezierPath bezierPath];
    path.lineWidth =4;
    path.lineCapStyle = kCGLineCapRound;
    [path moveToPoint:CGPointMake(0, 200)];

    [path addQuadCurveToPoint:CGPointMake(100, 200) controlPoint:CGPointMake(50, 100)];
    [path addQuadCurveToPoint:CGPointMake(200, 200) controlPoint:CGPointMake(150, 300)];
    [path addQuadCurveToPoint:CGPointMake(300, 200) controlPoint:CGPointMake(250, 100)];

    [path stroke];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值