<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CAShapeLayer/lineDashPhase",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CAShapeLayer(py)lineDashPhase"
  },
  "title" : "lineDashPhase"
}
-->

# lineDashPhase

The dash phase applied to the shape’s path when stroked. Animatable.

```
var lineDashPhase: CGFloat { get set }
```

## Discussion

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

Default is `0`.

The following code shows how you can create a “marching ant” effect by adding an animation to a shape layer that animates its [`lineDashPhase`](/documentation/QuartzCore/CAShapeLayer/lineDashPhase) from `0` to the sum of the segment lengths of its [`lineDashPattern`](/documentation/QuartzCore/CAShapeLayer/lineDashPattern).

```swift
let shapeLayer = CAShapeLayer()
shapeLayer.strokeColor = UIColor.black.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineWidth = 5
shapeLayer.lineDashPattern = [10,5,5,5]
     
let path = CGMutablePath()
path.addLines(between: [CGPoint(x: 0, y: 100),
                        CGPoint(x: 640, y: 100)])
shapeLayer.path = path
     
let lineDashAnimation = CABasicAnimation(keyPath: "lineDashPhase")
lineDashAnimation.fromValue = 0
lineDashAnimation.toValue = shapeLayer.lineDashPattern?.reduce(0) { $0 + $1.intValue }
lineDashAnimation.duration = 1
lineDashAnimation.repeatCount = Float.greatestFiniteMagnitude
     
shapeLayer.add(lineDashAnimation, forKey: nil)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)