我使用CAShapeLayer画一个半圆,我希望在开始时有一个kCGLineCapRound,在结尾有一个kCGLineCapButt。我怎么能这样做?
UIBezierPath *circlePathMax = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:radius startAngle:angle1 endAngle:angle2 clockwise:YES];
CAShapeLayer *circleMax;
circleMax = [CAShapeLayer layer];
circleMax.path = circlePathMax.CGPath;
circleMax.lineCap = kCALineCapRound;
circleMax.fillColor = [UIColor clearColor].CGColor;
circleMax.lineWidth = 10;
circleMax.strokeColor = [UIColor colorWithRed:255.0/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:0.7f].CGColor;
circleMax.zPosition = 3;
[self.view.layer addSublayer:circleMax];
我只能指定一个通用lineCap
答案 0 :(得分:0)
这是我使用的技巧。在我的情况下,我必须在渐变半圆的imageView顶部绘制具有透明度的半圆。这使我可以将.butt和背景颜色(带有alpha分量)用作strokeColor来“隐藏”方形角。
let circleMin = CAShapeLayer.init()
let circlePathMin = UIBezierPath.init(arcCenter: myCenter, radius: myRadius, startAngle: startingAngle, endAngle: endingAngle, clockwise: true)
circleMin.path = circlePathMin.cgPath
circleMin.lineCap = .butt
circleMin.fillColor = UIColor.clear.cgColor
circleMin.lineWidth = 14
circleMin.strokeColor = self.containerView.backgroundColor?.withAlphaComponent(0.7).cgColor
circleMin.zPosition = 3
containerView.layer.addSublayer(circleMin)
答案 1 :(得分:0)
您可以使用lineCap .butt
,然后在semicircle
的最后画一个圆圈。