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

# drawShading(_:)

Fills the clipping path of a context with the specified shading.

```
func drawShading(_ shading: CGShading)
```

## Parameters

`shading`

A shading object. The shading object is retained; upon return, you may safely release it.

## Discussion

The preferred way to draw gradients is to use a CGGradient object. See [`CGGradient`](/documentation/CoreGraphics/CGGradient).

## See Also

[`drawRadialGradient(_:startCenter:startRadius:endCenter:endRadius:options:)`](/documentation/CoreGraphics/CGContext/drawRadialGradient(_:startCenter:startRadius:endCenter:endRadius:options:))

Paints a gradient fill that varies along the area defined by the provided starting and ending circles.

[`drawLinearGradient(_:start:end:options:)`](/documentation/CoreGraphics/CGContext/drawLinearGradient(_:start:end:options:))

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



---

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)