---
title: "MTColorRamp | Mobile sdk | Mobile sdk ios | Ios"
description: "Swift wrapper over the MapTiler SDK ColorRamp class."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# MTColorRamp

```
@MainActor
public final class MTColorRamp : @unchecked Sendable
```

Swift wrapper over the MapTiler SDK ColorRamp class.

-   `[identifier](#/s:11MapTilerSDK11MTColorRampC10identifierSSvp)`
    
    Undocumented
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public let identifier: String
    ```
    
-   `[init(options:)](#/s:11MapTilerSDK11MTColorRampC7optionsAcA0dE7OptionsV_tcfc)`
    
    Creates a custom color ramp using the provided options.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public convenience init(options: MTColorRampOptions)
    ```
    
-   `[init(min:max:stops:)](#/s:11MapTilerSDK11MTColorRampC3min3max5stopsACSdSg_AGSayAA0dE4StopVGtcfc)`
    
    Creates a custom color ramp using explicit values and stops.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public convenience init(min: Double? = nil, max: Double? = nil, stops: [MTColorRampStop])
    ```
    
-   `[preset(_:)](#/s:11MapTilerSDK11MTColorRampC6presetyAcA0dE6PresetOFZ)`
    
    Creates a color ramp from a built-in preset. The preset is cloned to keep the global preset untouched.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public static func preset(_ preset: MTColorRampPreset) -> MTColorRamp
    ```
    
-   `[fromArrayDefinition(_:)](#/s:11MapTilerSDK11MTColorRampC19fromArrayDefinitionyACSayAA0deG4StopVGFZ)`
    
    Creates a color ramp from the array definition.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public static func fromArrayDefinition(_ definition: [MTColorRampArrayStop]) -> MTColorRamp
    ```
    
-   `[getBounds(in:)](#/s:11MapTilerSDK11MTColorRampC9getBounds2inAA0deG0VAA9MTMapViewC_tYaKF)` Asynchronous
    
    Returns bounds of the color ramp.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func getBounds(in mapView: MTMapView) async throws -> MTColorRampBounds
    ```
    
-   `[getColor(at:smooth:in:)](#/s:11MapTilerSDK11MTColorRampC8getColor2at6smooth2inAA11MTRGBAColorVSd_SbAA9MTMapViewCtYaKF)` Asynchronous
    
    Returns the color at the provided value.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func getColor(
        at value: Double,
        smooth: Bool = true,
        in mapView: MTMapView
    ) async throws -> MTRGBAColor
    ```
    
-   `[getColorHex(at:smooth:includeAlpha:in:)](#/s:11MapTilerSDK11MTColorRampC11getColorHex2at6smooth12includeAlpha2inSSSd_S2bAA9MTMapViewCtYaKF)` Asynchronous
    
    Returns the color hex string at the provided value.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func getColorHex(
        at value: Double,
        smooth: Bool = true,
        includeAlpha: Bool = false,
        in mapView: MTMapView
    ) async throws -> String
    ```
    
-   `[getColorRelative(at:smooth:in:)](#/s:11MapTilerSDK11MTColorRampC16getColorRelative2at6smooth2inAA11MTRGBAColorVSd_SbAA9MTMapViewCtYaKF)` Asynchronous
    
    Returns the color for a relative value in \[0, 1\].
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func getColorRelative(
        at value: Double,
        smooth: Bool = true,
        in mapView: MTMapView
    ) async throws -> MTRGBAColor
    ```
    
-   `[getRawColorStops(in:)](#/s:11MapTilerSDK11MTColorRampC16getRawColorStops2inSayAA0dE4StopVGAA9MTMapViewC_tYaKF)` Asynchronous
    
    Returns raw stops backing the ramp.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func getRawColorStops(in mapView: MTMapView) async throws -> [MTColorRampStop]
    ```
    
-   `[clone(in:)](#/s:11MapTilerSDK11MTColorRampC5clone2inAcA9MTMapViewC_tYaKF)` Asynchronous
    
    Clones the color ramp.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func clone(in mapView: MTMapView) async throws -> MTColorRamp
    ```
    
-   `[reverse(clone:in:)](#/s:11MapTilerSDK11MTColorRampC7reverse5clone2inACSb_AA9MTMapViewCtYaKF)` Asynchronous
    
    Returns a ramp reversed in-place or cloned depending on the `clone` flag.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func reverse(clone: Bool = true, in mapView: MTMapView) async throws -> MTColorRamp
    ```
    
-   `[scale(min:max:clone:in:)](#/s:11MapTilerSDK11MTColorRampC5scale3min3max5clone2inACSd_SdSbAA9MTMapViewCtYaKF)` Asynchronous
    
    Scales the ramp to the given bounds.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func scale(
        min: Double,
        max: Double,
        clone: Bool = true,
        in mapView: MTMapView
    ) async throws -> MTColorRamp
    ```
    
-   `[setStops(_:clone:in:)](#/s:11MapTilerSDK11MTColorRampC8setStops_5clone2inACSayAA0dE4StopVG_SbAA9MTMapViewCtYaKF)` Asynchronous
    
    Replaces the stops on the ramp.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func setStops(
        _ stops: [MTColorRampStop],
        clone: Bool = true,
        in mapView: MTMapView
    ) async throws -> MTColorRamp
    ```
    
-   `[resample(_:samples:in:)](#/s:11MapTilerSDK11MTColorRampC8resample_7samples2inAcA0dE14ResampleMethodO_SiAA9MTMapViewCtYaKF)` Asynchronous
    
    Resamples the ramp using the provided method and sample count.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func resample(
        _ method: MTColorRampResampleMethod,
        samples: Int = 15,
        in mapView: MTMapView
    ) async throws -> MTColorRamp
    ```
    
-   `[transparentStart(in:)](#/s:11MapTilerSDK11MTColorRampC16transparentStart2inAcA9MTMapViewC_tYaKF)` Asynchronous
    
    Prepends a transparent stop at the beginning of the ramp.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func transparentStart(in mapView: MTMapView) async throws -> MTColorRamp
    ```
    
-   `[hasTransparentStart(in:)](#/s:11MapTilerSDK11MTColorRampC19hasTransparentStart2inSbAA9MTMapViewC_tYaKF)` Asynchronous
    
    Returns true if the first stop is transparent.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func hasTransparentStart(in mapView: MTMapView) async throws -> Bool
    ```
    
-   `[getCanvasStrip(options:in:)](#/s:11MapTilerSDK11MTColorRampC14getCanvasStrip7options2inSo7UIImageCAA0degH7OptionsV_AA9MTMapViewCtYaKF)` Asynchronous
    
    Renders the ramp to a canvas strip and returns it as `UIImage`.
    
    #### Declaration
    
    Swift
    
    ```
    @MainActor
    public func getCanvasStrip(
        options: MTColorRampCanvasStripOptions = MTColorRampCanvasStripOptions(),
        in mapView: MTMapView
    ) async throws -> UIImage
    ```
    
-   `[getColor(at:smooth:in:completionHandler:)](#/s:11MapTilerSDK11MTColorRampC8getColor2at6smooth2in17completionHandlerySd_SbAA9MTMapViewCys6ResultOyAA11MTRGBAColorVAA7MTErrorOGcSgtF)`
    
    Deprecated completion-based variant of `[getColor(at:smooth:in:)](https://docs.maptiler.com/mobile-sdk/ios/api/Classes/MTColorRamp/#/s:11MapTilerSDK11MTColorRampC8getColor2at6smooth2inAA11MTRGBAColorVSd_SbAA9MTMapViewCtYaKF)`.
    
    #### Declaration
    
    Swift
    
    ```
    @available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
    @MainActor
    func getColor(
        at value: Double,
        smooth: Bool = true,
        in mapView: MTMapView,
        completionHandler: ((Result<MTRGBAColor, MTError>) -> Void)? = nil
    )
    ```
    
-   `[getColorHex(at:smooth:includeAlpha:in:completionHandler:)](#/s:11MapTilerSDK11MTColorRampC11getColorHex2at6smooth12includeAlpha2in17completionHandlerySd_S2bAA9MTMapViewCys6ResultOySSAA7MTErrorOGcSgtF)`
    
    Deprecated completion-based variant of `[getColorHex(at:smooth:includeAlpha:in:)](https://docs.maptiler.com/mobile-sdk/ios/api/Classes/MTColorRamp/#/s:11MapTilerSDK11MTColorRampC11getColorHex2at6smooth12includeAlpha2inSSSd_S2bAA9MTMapViewCtYaKF)`.
    
    #### Declaration
    
    Swift
    
    ```
    @available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
    @MainActor
    func getColorHex(
        at value: Double,
        smooth: Bool = true,
        includeAlpha: Bool = false,
        in mapView: MTMapView,
        completionHandler: ((Result<String, MTError>) -> Void)? = nil
    )
    ```
    
-   `[getBounds(in:completionHandler:)](#/s:11MapTilerSDK11MTColorRampC9getBounds2in17completionHandleryAA9MTMapViewC_ys6ResultOyAA0deG0VAA7MTErrorOGcSgtF)`
    
    Deprecated completion-based variant of `[getBounds(in:)](https://docs.maptiler.com/mobile-sdk/ios/api/Classes/MTColorRamp/#/s:11MapTilerSDK11MTColorRampC9getBounds2inAA0deG0VAA9MTMapViewC_tYaKF)`.
    
    #### Declaration
    
    Swift
    
    ```
    @available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
    @MainActor
    func getBounds(
        in mapView: MTMapView,
        completionHandler: ((Result<MTColorRampBounds, MTError>) -> Void)? = nil
    )
    ```
    
-   `[getRawColorStops(in:completionHandler:)](#/s:11MapTilerSDK11MTColorRampC16getRawColorStops2in17completionHandleryAA9MTMapViewC_ys6ResultOySayAA0dE4StopVGAA7MTErrorOGcSgtF)`
    
    Deprecated completion-based variant of `[getRawColorStops(in:)](https://docs.maptiler.com/mobile-sdk/ios/api/Classes/MTColorRamp/#/s:11MapTilerSDK11MTColorRampC16getRawColorStops2inSayAA0dE4StopVGAA9MTMapViewC_tYaKF)`.
    
    #### Declaration
    
    Swift
    
    ```
    @available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
    @MainActor
    func getRawColorStops(
        in mapView: MTMapView,
        completionHandler: ((Result<[MTColorRampStop], MTError>) -> Void)? = nil
    )
    ```
    
-   `[clone(in:completionHandler:)](#/s:11MapTilerSDK11MTColorRampC5clone2in17completionHandleryAA9MTMapViewC_ys6ResultOyAcA7MTErrorOGcSgtF)`
    
    Deprecated completion-based variant of `[clone(in:)](https://docs.maptiler.com/mobile-sdk/ios/api/Classes/MTColorRamp/#/s:11MapTilerSDK11MTColorRampC5clone2inAcA9MTMapViewC_tYaKF)`.
    
    #### Declaration
    
    Swift
    
    ```
    @available(iOS, deprecated: 16.0, message: "Prefer the async version for modern concurrency handling")
    @MainActor
    func clone(
        in mapView: MTMapView,
        completionHandler: ((Result<MTColorRamp, MTError>) -> Void)? = nil
    )
    ```
