Search code examples
ioscashapelayer

CAShapeLayer dashed line start with margin


Is it possible to start drawing dashed CAShapeLayer line with some margin? I am connect couple dashed lines at an angle.

It would be great if my dash could start at half dash length. So if

lineDashPattern = [8, 8]

then dash line should start drawing with 4 margin


Solution

  • You should use lineDashPhase. It specifies an offset, in user space applied to the line dash pattern

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

    shapeLayer1.lineDashPhase = 8
    

    enter image description here