<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGPattern",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@T@CGPatternRef"
  },
  "title" : "CGPattern"
}
-->

# CGPattern

A 2D pattern to be used for drawing graphics paths.

```
class CGPattern
```

## Overview

Core Graphics tiles the pattern cell for you, based on parameters you specify when you call [`init(info:bounds:matrix:xStep:yStep:tiling:isColored:callbacks:)`](/documentation/CoreGraphics/CGPattern/init(info:bounds:matrix:xStep:yStep:tiling:isColored:callbacks:)).

To create a dashed line, see [`CGContextSetLineDash`](/documentation/CoreGraphics/CGContextSetLineDash).

## Topics

### Creating a Pattern

[`init(info:bounds:matrix:xStep:yStep:tiling:isColored:callbacks:)`](/documentation/CoreGraphics/CGPattern/init(info:bounds:matrix:xStep:yStep:tiling:isColored:callbacks:))

Creates a pattern object.

### Retaining and Releasing a Pattern

[`CGPatternRetain`](/documentation/CoreGraphics/CGPatternRetain)

Increments the retain count of a Core Graphics pattern.

[`CGPatternRelease`](/documentation/CoreGraphics/CGPatternRelease)

Decrements the retain count of a Core Graphics pattern.

### Callbacks

[`CGPatternCallbacks`](/documentation/CoreGraphics/CGPatternCallbacks)

A structure that holds a version and two callback functions for drawing a custom pattern.

[`CGPatternDrawPatternCallback`](/documentation/CoreGraphics/CGPatternDrawPatternCallback)

Draws a pattern cell.

[`CGPatternReleaseInfoCallback`](/documentation/CoreGraphics/CGPatternReleaseInfoCallback)

Release private data or resources associated with the pattern.

### Constants

[`CGPatternTiling`](/documentation/CoreGraphics/CGPatternTiling)

Different methods for rendering a tiled pattern.

### Working with Core Foundation Types

[`typeID`](/documentation/CoreGraphics/CGPattern/typeID)

Returns the type identifier for Core Graphics patterns.

## See Also

  [Quartz 2D Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066)



---

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)