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

# CGShading

A definition for a smooth transition between colors, controlled by a custom function you provide, for drawing radial and axial gradient fills.

```
class CGShading
```

## Overview

Shading means to fill using a smooth transition between colors across an area. You create a shading using a custom function with a [`CGFunction`](/documentation/CoreGraphics/CGFunction) instance. To paint with a Core Graphics shading, you call [`drawShading(_:)`](/documentation/CoreGraphics/CGContext/drawShading(_:)). This function fills the current clipping path using the specified color gradient, calling your parametric function repeatedly as it draws.

An alternative to using a `CGShading` instance is to use the [`CGGradient`](/documentation/CoreGraphics/CGGradient) type. For applications that run in macOS 10.5 and later, `CGGradient` objects are much simpler to use.

## Topics

### Creating Shading Objects

[`init(axialSpace:start:end:function:extendStart:extendEnd:)`](/documentation/CoreGraphics/CGShading/init(axialSpace:start:end:function:extendStart:extendEnd:))

Creates a shading object to use for axial shading.

[`init(radialSpace:start:startRadius:end:endRadius:function:extendStart:extendEnd:)`](/documentation/CoreGraphics/CGShading/init(radialSpace:start:startRadius:end:endRadius:function:extendStart:extendEnd:))

Creates a shading object to use for radial shading.

### Retaining and Releasing Shading Objects

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

Increments the retain count of a shading object.

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

Decrements the retain count of a shading object.

### Working with Core Foundation Types

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

Returns the Core Foundation type identifier for Core Graphics shading objects.

## 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)