关于UIBezierPath的使用

  使用UIBezierPath类可以创建基于矢量的路径。此类是Core Graphics框架关于path的一个封装。使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线段组成的形状。

例:

先看效果图:


    UIColor *color = [UIColor redColor] ;

    [color set]; //设置颜色

    //方形

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

    //图形的宽度

    square.lineWidth = 1.0;

    //边框

    [square stroke];

    

    //椭圆

    UIBezierPath* ellipse = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(20, 100, 150, 50)];

    [ellipse fill];

    //圆形

    //参数: 圆心坐标  半径  开始角度  结束角度  方向是:顺、逆时针

    // = 2pi = 360°  M_PI_4 = 圆的/8 = 45°

    //这里是顺时针算角度

    UIBezierPath* circular = [UIBezierPath bezierPathWithArcCenter:CGPointMake(25, 180) radius:25 startAngle:0 endAngle:M_PI_4 clockwise:NO];

    [circular stroke];

    

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

    UIBezierPath* twoCurve = [UIBezierPath bezierPath];

    //启示位置

    [twoCurve moveToPoint:CGPointMake(20, 220)];

    //终止位置  曲线方形位置

    [twoCurve addQuadCurveToPoint:CGPointMake(20, 260) controlPoint:CGPointMake(120, 260)];

    [twoCurve stroke];

    

    /*----绘制三次贝塞尔曲线----*/

    UIBezierPath* thridCurve = [UIBezierPath bezierPath];

    //启示位置

    [thridCurve moveToPoint:CGPointMake(10, 320)];

    //终止位置   第一曲线方形位置  第二曲线方形位置

    [thridCurve addCurveToPoint:CGPointMake(310, 320) controlPoint1:CGPointMake(110,220) controlPoint2:CGPointMake(210, 420)];

    [thridCurve stroke];


    /*----自定义绘图----*/   五边形

    UIBezierPath* drawPath = [UIBezierPath bezierPath];

    [drawPath moveToPoint:CGPointMake(100.0, 400.0)];

    [drawPath addLineToPoint:CGPointMake(200.0, 440.0)];

    [drawPath addLineToPoint:CGPointMake(160, 540)];

    [drawPath addLineToPoint:CGPointMake(40.0, 540)];

    [drawPath addLineToPoint:CGPointMake(0.0, 440.0)];

    //设置颜色

    [[UIColor blackColor] setStroke];

    //结束绘图

    [drawPath closePath];

    [drawPath stroke];



方法  原理图解:

- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;



- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;



- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise NS_AVAILABLE_IOS(4_0);











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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值