<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/MeshGradient/init(width:height:locations:colors:background:smoothsColors:colorSpace:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI12MeshGradientV5width6height9locations6colors10background13smoothsColors10colorSpaceACSi_SiAC9LocationsOAC0K0OAA5ColorVSbAA0D0V0oM0Vtcfc"
  },
  "title" : "init(width:height:locations:colors:background:smoothsColors:colorSpace:)"
}
-->

# init(width:height:locations:colors:background:smoothsColors:colorSpace:)

Creates a new gradient mesh specified as a 2D grid of colored
vertices.

```
nonisolated init(width: Int, height: Int, locations: MeshGradient.Locations, colors: MeshGradient.Colors, background: Color = .clear, smoothsColors: Bool = true, colorSpace: Gradient.ColorSpace = .device)
```

## Parameters

`width`

the width of the mesh, i.e. the number of vertices
per row.

`height`

the height of the mesh, i.e. the number of vertices
per column.

`locations`

the array of locations, containing `width x height` elements.

`colors`

the array of colors, containing `width x height`
elements.

`background`

the background color, this fills any points
outside the defined vertex mesh.

`smoothsColors`

whether cubic (smooth) interpolation should
be used for the colors in the mesh (rather than only for the
shape of the mesh).

`colorSpace`

the color space in which to interpolate vertex
colors.

---

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)