<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIGraphicsRendererContext/clip(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIGraphicsRendererContext(im)clipToRect:"
  },
  "title" : "clip(to:)"
}
-->

# clip(to:)

Sets the clipping mask for the drawing context to the specified rectangle.

```
func clip(to rect: CGRect)
```

## Parameters

`rect`

The rectangle to which the drawing context is clipped, specified in the Core Graphics coordinate space with values in points.

## Discussion

To restrict the active drawing area to the specified rectangle, call this method before executing drawing commands.

To use a more complex shape as a clipping mask, use the <doc://com.apple.documentation/documentation/CoreGraphics/CGContext/clip(to:mask:)> method on the underlying Core Graphics context, accessed through the [`cgContext`](/documentation/UIKit/UIGraphicsRendererContext/cgContext) property.

---

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)