即使使用kCGLineCapRound,也无法在UIBezierPath Arc中圆角

12

我无法在使用UIBezierPath创建的弧线上显示圆角。无论是否设置kCGLineCapRound,它都仍然是完全方形的。

这个问题应该与这个主题相同,但解决方案不起作用。

下面是我在viewWillAppear中为测试目的而编写的示例代码:

int radius = 100;
CAShapeLayer *arc = [CAShapeLayer layer];
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 50) radius:radius startAngle:M_PI endAngle:M_PI/150 clockwise:YES];
path.lineCapStyle = kCGLineCapRound;

arc.path = path.CGPath;
arc.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius, CGRectGetMidY(self.view.frame)-radius);
arc.fillColor = [UIColor clearColor].CGColor;
arc.strokeColor = [UIColor purpleColor].CGColor;
arc.lineWidth = 10.0f;
arc.cornerRadius = 3.0f;

这是它的外观:

whyy

我很无助,所以我会感激任何帮助。谢谢大家。

1个回答

35

使用 CAShapeLayerlineCap 属性而不是路径的 lineCapStyle

arc.lineCap = kCALineCapRound;

如果您正在调用路径的stroke方法(例如,如果您在drawRect中执行此操作或手动绘制UIGraphicsContext),则请在UIBezierPath中设置像端点和连线样式等属性。但是,在使用CAShapeLayer时,这些属性应设置在形状图层上而不是路径上。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接