<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CAGradientLayer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CAGradientLayer"
  },
  "title" : "CAGradientLayer"
}
-->

# CAGradientLayer

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

```
class CAGradientLayer
```

## 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° (<doc://com.apple.documentation/documentation/Swift/FloatingPoint/pi> ⁄ `2` radians) gives a horizontal gradient.

```objc
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.

![Color gradient layer](images/com.apple.quartzcore/media-2825193@2x.png)

## Topics

### Gradient Style Properties

[`colors`](/documentation/QuartzCore/CAGradientLayer/colors)

An array of `CGColorRef` objects defining the color of each gradient stop. Animatable.

[`locations`](/documentation/QuartzCore/CAGradientLayer/locations)

An optional array of NSNumber objects defining the location of each gradient stop. Animatable.

[`endPoint`](/documentation/QuartzCore/CAGradientLayer/endPoint)

The end point of the gradient when drawn in the layer’s coordinate space. Animatable.

[`startPoint`](/documentation/QuartzCore/CAGradientLayer/startPoint)

The start point of the gradient when drawn in the layer’s coordinate space. Animatable.

[`type`](/documentation/QuartzCore/CAGradientLayer/type)

Style of gradient drawn by the layer.

### Constants

[Gradient Types](/documentation/QuartzCore/gradient-types)

The style of gradient drawn by the layer.



---

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)