<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/GraphicsContext/clipToLayer(opacity:options:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI15GraphicsContextV11clipToLayer7opacity7options7contentySd_AC11ClipOptionsVyACzKXEtKF"
  },
  "title" : "clipToLayer(opacity:options:content:)"
}
-->

# clipToLayer(opacity:options:content:)

Adds a clip shape that you define in a new layer to the context’s array
of clip shapes.

```
mutating func clipToLayer(opacity: Double = 1, options: GraphicsContext.ClipOptions = ClipOptions(), content: (inout GraphicsContext) throws -> Void) rethrows
```

## Parameters

`opacity`

A value that SwiftUI uses to multiply the alpha channel of
the rasterized layer that you define in the `content` closure. The
alpha values that result define the clip shape.

`options`

A set of options that tell SwiftUI how to interpret the
clip shape. For example, you can invert the clip
shape by setting the [`inverse`](/documentation/SwiftUI/GraphicsContext/ClipOptions/inverse) option.

`content`

A closure that receives as input a new [`GraphicsContext`](/documentation/SwiftUI/GraphicsContext),
which represents a new transparency layer. The alpha channel of
content that you draw into this context, multiplied by the `opacity`
parameter, defines the clip shape.

## Discussion

Call this method to add a shape to the array of clip shapes that
the context uses to define a clipping mask. Shapes that you add
affect only subsequent drawing operations.

---

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)