您的位置:首页 > 产品设计 > UI/UE

关于UIBezierPath的使用

2015-09-28 14:35 399 查看
  使用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
bdb6
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);

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: