<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ModelIO",
  "identifier" : "/documentation/ModelIO/MDLColorSwatchTexture/init(colorGradientFrom:to:name:textureDimensions:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Model I/O"
    ],
    "preciseIdentifier" : "c:objc(cs)MDLColorSwatchTexture(im)initWithColorGradientFrom:toColor:name:textureDimensions:"
  },
  "title" : "init(colorGradientFrom:to:name:textureDimensions:)"
}
-->

# init(colorGradientFrom:to:name:textureDimensions:)

Initializes a texture that creates a vertical gradient between two colors.

```
init(colorGradientFrom color1: CGColor, to color2: CGColor, name: String?, textureDimensions: vector_int2)
```

## Parameters

`color1`

The color at the top of the gradient.

`color2`

The color at the bottom of the gradient.

`name`

The [`name`](/documentation/ModelIO/MDLNamed/name) property for the new texture object.

`textureDimensions`

The texel dimensions (width and height) of the texture image.

## Return Value

A new color swatch texture object.

## Discussion

Model I/O interpolates between the `color1` and `color2` colors by hue, saturation, and lightness to create a color gradient when generating texture data.

This initializer does not generate texel data; the [`MDLColorSwatchTexture`](/documentation/ModelIO/MDLColorSwatchTexture) class automatically generates data and caches it for reuse when you use one of the [`MDLTexture`](/documentation/ModelIO/MDLTexture) methods listed in Accessing Texture Data.

---

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)