<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "tvOS: 14.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "MapKit",
  "identifier" : "/documentation/MapKit/MKGradientPolylineRenderer/setColors(_:locations:)-3xrou",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "MapKit"
    ],
    "preciseIdentifier" : "s:So26MKGradientPolylineRendererC6MapKitE9setColors_9locationsySaySo7UIColorCG_Say14CoreFoundation7CGFloatVGtF"
  },
  "title" : "setColors(_:locations:)"
}
-->

# setColors(_:locations:)

Sets the iOS colors and corresponding unit distance values to create gradients.

```
func setColors(_ colors: [UIColor], locations: [CGFloat])
```

## Parameters

`colors`

An array of colors making up the transition points of the gradient.

`locations`

An array of unit distance values that correspond to the provided colors.

## Discussion

The unit distance value of `0` represents the start of the polyline, and `1` represents the end of the polyline. A gradient may have any number of steps along the length of the polyline.

To determine a location along the polyline, use [`location(atPointIndex:)`](/documentation/MapKit/MKMultiPoint/location(atPointIndex:)), or retrieve a set of locations using [`locations`](/documentation/MapKit/MKGradientPolylineRenderer/locations-7k6qz).

---

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)