<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGContext/drawLinearGradient(_:start:end:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGContextDrawLinearGradient"
  },
  "title" : "drawLinearGradient(_:start:end:options:)"
}
-->

# drawLinearGradient(_:start:end:options:)

Paints a gradient fill that varies along the line defined by the provided starting and ending points.

```
func drawLinearGradient(_ gradient: CGGradient, start startPoint: CGPoint, end endPoint: CGPoint, options: CGGradientDrawingOptions)
```

## Parameters

`gradient`

A gradient object.

`startPoint`

The coordinate that defines the starting point of the gradient.

`endPoint`

The coordinate that defines the ending point of the gradient.

`options`

Option flags ([`drawsBeforeStartLocation`](/documentation/CoreGraphics/CGGradientDrawingOptions/drawsBeforeStartLocation) or [`drawsAfterEndLocation`](/documentation/CoreGraphics/CGGradientDrawingOptions/drawsAfterEndLocation)) that control whether the fill is extended beyond the starting or ending point.

## Discussion

The color at location 0 in the CGGradient object is mapped to the starting point. The color at location 1 in the CGGradient object is mapped to the ending point. Colors are linearly interpolated between these two points based on the location values of the gradient. The option flags control whether the gradient is drawn before the start point or after the end point.

---

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)