---
title: "setLineDash(phase:lengths:)"
framework: coregraphics
role: symbol
role_heading: Instance Method
path: "coregraphics/cgcontext/setlinedash(phase:lengths:)"
---

# setLineDash(phase:lengths:)

Sets the pattern for drawing dashed lines.

## Declaration

```swift
func setLineDash(phase: CGFloat, lengths: [CGFloat])
```

## Parameters

- `phase`: A value that specifies how far into the dash pattern the line starts, in units of the user space. For example, a value of 0 draws a line starting with the beginning of a dash pattern, and a value of 3 means the line is drawn with the dash pattern starting at three units from its beginning.
- `lengths`: An array of values that specify the lengths, in user space coordinates, of the painted and unpainted segments of the dash pattern. For example, the array [2,3] sets a dash pattern that alternates between a 2-unit-long painted segment and a 3-unit-long unpainted segment. The array [1,3,4,2] sets the pattern to a 1-unit painted segment, a 3-unit unpainted segment, a 4-unit painted segment, and a 2-unit unpainted segment.Pass an empty array to clear the dash pattern so that all stroke drawing in the context uses solid lines.

## See Also

### Setting Path Drawing Options

- [setAllowsAntialiasing(_:)](coregraphics/cgcontext/setallowsantialiasing(_:).md)
- [setFlatness(_:)](coregraphics/cgcontext/setflatness(_:).md)
- [setLineCap(_:)](coregraphics/cgcontext/setlinecap(_:).md)
- [setLineJoin(_:)](coregraphics/cgcontext/setlinejoin(_:).md)
- [setLineWidth(_:)](coregraphics/cgcontext/setlinewidth(_:).md)
- [setMiterLimit(_:)](coregraphics/cgcontext/setmiterlimit(_:).md)
- [setPatternPhase(_:)](coregraphics/cgcontext/setpatternphase(_:).md)
- [setFillPattern(_:colorComponents:)](coregraphics/cgcontext/setfillpattern(_:colorcomponents:).md)
- [setShouldAntialias(_:)](coregraphics/cgcontext/setshouldantialias(_:).md)
