CAShapeLayer 虚线以边距开始

CAShapeLayer dashed line start with margin

是否可以开始绘制带有一定边距的虚线 CAShapeLayer?我以一定角度连接一对虚线。

如果我的破折号能以破折号的一半长度开始就好了。所以如果

lineDashPattern = [8, 8]

那么虚线应该以 4 个边距开始绘制

你应该使用lineDashPhase。它指定一个偏移量,在用户 space 中应用于虚线模式

Line dash phase specifies how far into the dash pattern the line starts.

shapeLayer1.lineDashPhase = 8