美文网首页
(转载)UIBezierPath画圆弧 addArcWithCe

(转载)UIBezierPath画圆弧 addArcWithCe

作者: 雾霾下的天空 | 来源:发表于2018-03-09 15:49 被阅读24次

    转载
    UIBezierPath通过

    • (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise

    可以画出一段弧线。

    看下各个参数的意义:

    center:圆心的坐标

    radius:半径

    startAngle:起始的弧度

    endAngle:圆弧结束的弧度

    clockwise:YES为顺时针,No为逆时针

    方法里面主要是理解startAngle与endAngle,刚开始我搞不清楚一段圆弧从哪算起始和终止,比如弧度为0的话,是从上下左右哪个点开始算

    image

    [objc] view plaincopy

    <embed id="ZeroClipboardMovie_1" src="http://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">

    1. CAShapeLayer *layer = [[CAShapeLayer alloc] init];

    2. layer.name = @"Radius";

    3. CGFloat lineWidth = 10;

    4. UIBezierPath *path = [UIBezierPath bezierPath];

    5. path.lineWidth = lineWidth;

    6. path.lineCapStyle = kCGLineCapButt;

    7. CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);

    8. CGFloat radius = (self.bounds.size.width - lineWidth)/2;

    9. CGFloat startAngle = -((float)M_PI)/7; //

    10. CGFloat endAngle = ((float)M_PI)-startAngle ;

    11. [[UIColor whiteColor] set];

    12. [path addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];

    13. [path stroke];

    14. [path closePath];

    image

    相关文章

      网友评论

          本文标题:(转载)UIBezierPath画圆弧 addArcWithCe

          本文链接:https://www.haomeiwen.com/subject/ojzpfftx.html