---
title: CAGradientLayer
framework: quartzcore
role: symbol
role_heading: Class
path: quartzcore/cagradientlayer
---

# CAGradientLayer

A layer that draws a color gradient over its background color, filling the shape of the layer.

## Declaration

```swift
class CAGradientLayer
```

## Overview

Overview You use a gradient layer to create a color gradient containing an arbitrary number of colors. By default, the colors are spread uniformly across the layer, but you can optionally specify locations for control over the color positions through the gradient. The following code shows how to create a gradient layer containing four colors that are evenly distributed through the gradient. Rotating the layer by 90° (pi ⁄ 2 radians) gives a horizontal gradient. gradientLayer.colors = [UIColor.red.cgColor,                         UIColor.yellow.cgColor,                         UIColor.green.cgColor,                         UIColor.blue.cgColor]       gradientLayer.transform = CATransform3DMakeRotation(CGFloat.pi / 2, 0, 0, 1) The following figure shows the appearance of the gradient layer.

## Topics

### Gradient Style Properties

- [colors](quartzcore/cagradientlayer/colors.md)
- [locations](quartzcore/cagradientlayer/locations.md)
- [endPoint](quartzcore/cagradientlayer/endpoint.md)
- [startPoint](quartzcore/cagradientlayer/startpoint.md)
- [type](quartzcore/cagradientlayer/type.md)

### Constants

- [Gradient Types](quartzcore/gradient-types.md)

## Relationships

### Inherits From

- [CALayer](quartzcore/calayer.md)

### Conforms To

- [CAMediaTiming](quartzcore/camediatiming.md)
- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Text, Shapes, and Gradients

- [CATextLayer](quartzcore/catextlayer.md)
- [CAShapeLayer](quartzcore/cashapelayer.md)
