---
title: "clipToLayer(opacity:options:content:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/graphicscontext/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.

## Declaration

```swift
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 doc://com.apple.SwiftUI/documentation/SwiftUI/GraphicsContext/ClipOptions/inverse option.
- `content`: A closure that receives as input a new doc://com.apple.SwiftUI/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

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.

## See Also

### Masking

- [clip(to:style:options:)](swiftui/graphicscontext/clip(to:style:options:).md)
- [clipBoundingRect](swiftui/graphicscontext/clipboundingrect.md)
- [GraphicsContext.ClipOptions](swiftui/graphicscontext/clipoptions.md)
