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

# CGGradient

A definition for a smooth transition between colors for drawing radial and axial gradient fills.

```
class CGGradient
```

## Overview

A gradient defines a smooth transition between colors across an area. A `CGGradient` has a color space, two or more colors, and a location for each color. The color space cannot be a pattern or indexed color space, otherwise it can be any Core Graphics color space ([`CGColorSpace`](/documentation/CoreGraphics/CGColorSpace)).

Colors can be provided as component values (such as red, green, blue) or as Core Graphics color objects ([`CGColor`](/documentation/CoreGraphics/CGColor)). Component values can vary from 0.0 to 1.0, designating the proportion of the component present in the color.

A location is a normalized value. When it comes time to paint the gradient, Core Graphics maps the normalized location values to the points in coordinate space that you provide.

For more precise control over gradients, see [`CGShading`](/documentation/CoreGraphics/CGShading).

## Topics

### Creating Gradient Instances

[`init(colorSpace:colorComponents:locations:count:)`](/documentation/CoreGraphics/CGGradient/init(colorSpace:colorComponents:locations:count:))

Creates a CGGradient object from a color space and the provided color components and locations.

[`init(colorsSpace:colors:locations:)`](/documentation/CoreGraphics/CGGradient/init(colorsSpace:colors:locations:))

Creates a gradient object from a color space and the provided color objects and locations.

### Retaining and Releasing a Gradient

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

Decrements the retain count of a CGGradient object.

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

Increments the retain count of a CGGradient object.

### Working with Core Foundation Types

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

Returns the Core Foundation type identifier for CGGradient objects.

### Constants

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

Drawing locations for gradients.



---

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)