Ios 如何制作圆弧的拐角

Ios 如何制作圆弧的拐角,ios,objective-c,geometry,Ios,Objective C,Geometry,我做了一个像下面这样的弧。通过指定半径、开始角度、结束角度 CGContextAddArc(ctx, self.frame.size.width/2 , self.frame.size.height/2, self.radius, 2*M_PI, 3*M_PI/2-ToRad(angle), 0); 现在我想把拱门的拐角弄圆。所以需要在两端画圆。因为我使用的是框架尺寸,所以给常数行不通 尝试将图形状态参数CGContextSetLineJoin设置为round:CGContextS

我做了一个像下面这样的弧。通过指定半径、开始角度、结束角度

    CGContextAddArc(ctx, self.frame.size.width/2  , self.frame.size.height/2,
 self.radius, 2*M_PI, 3*M_PI/2-ToRad(angle), 0);
现在我想把拱门的拐角弄圆。所以需要在两端画圆。因为我使用的是框架尺寸,所以给常数行不通


尝试将图形状态参数CGContextSetLineJoin设置为round:
CGContextSetLineCap(ctx,kCGLineCapRound)

这是我根据你的问题所做的研究。该方法驻留在drawRect:method中,我编写了一个简短的方法对其进行抽象,以便只为该方法提供参数startAngle、endAngle和radius。当然可以提炼

我提供了这个方法输出的图片

- (void)drawRect:(CGRect)rect {
    float startAngle = 0;
    float endAngle = 60;
    float radius = 50.0;

    CGContextRef ctx = [self drawRoundedArcWithStartAngle:startAngle endAngle:endAngle radius:radius];
    CGContextStrokePath(ctx);
}

- (CGContextRef)drawRoundedArcWithStartAngle:(float)startAngle endAngle:(float)endAngle radius:(float)radius {

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //    [CGContextAddArc(ctx, self.frame.size.width/2  , self.frame.size.height/2, radius, 2*M_PI, 3*M_PI/2-(angle * M_PI / 180), 0)];

    CGContextAddArc(ctx, self.frame.size.width/ 2, self.frame.size.height/2, radius, (startAngle * M_PI / 180), (endAngle * M_PI / 180), 0);
    CGContextSetRGBStrokeColor(ctx, 0.0, 0.0, 0.0, 1.0);
    CGContextSetLineWidth(ctx, 20.0f);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    return ctx;
}
希望有帮助


您可以通过

目标-C

CGContextSetLineCap(context, kCGLineCapRound);
迅捷的


图形库是否提供笔特征设置?就像Windows GDI中的PS_ENDCAP_ROUND。
context?.setLineCap(.round)
context?.addArc(center: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true/false)