---
title: CGGradient
framework: coregraphics
role: symbol
role_heading: Class
path: coregraphics/cggradient
---

# CGGradient

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

## Declaration

```swift
class CGGradient
```

## Overview

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). Colors can be provided as component values (such as red, green, blue) or as Core Graphics color objects (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.

## Topics

### Creating Gradient Instances

- [init(colorSpace:colorComponents:locations:count:)](coregraphics/cggradient/init(colorspace:colorcomponents:locations:count:).md)
- [init(colorsSpace:colors:locations:)](coregraphics/cggradient/init(colorsspace:colors:locations:).md)

### Working with Core Foundation Types

- [typeID](coregraphics/cggradient/typeid.md)

### Initializers

- [init(headroom:colorSpace:colorComponents:locations:count:)](coregraphics/cggradient/init(headroom:colorspace:colorcomponents:locations:count:).md)

### Instance Properties

- [contentHeadroom](coregraphics/cggradient/contentheadroom.md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)

## See Also

### Utility and Support Classes

- [CGDataConsumer](coregraphics/cgdataconsumer.md)
- [CGDataProvider](coregraphics/cgdataprovider.md)
- [CGShading](coregraphics/cgshading.md)
- [CGFunction](coregraphics/cgfunction.md)
- [CGPattern](coregraphics/cgpattern.md)
