<!--
{
  "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/UIGraphicsRenderer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIGraphicsRenderer"
  },
  "title" : "UIGraphicsRenderer"
}
-->

# UIGraphicsRenderer

An abstract base class for creating graphics renderers.

```
class UIGraphicsRenderer
```

## Overview

Don’t use [`UIGraphicsRenderer`](/documentation/UIKit/UIGraphicsRenderer) directly. Instead, either use one of the concrete subclasses ([`UIGraphicsImageRenderer`](/documentation/UIKit/UIGraphicsImageRenderer) or [`UIGraphicsPDFRenderer`](/documentation/UIKit/UIGraphicsPDFRenderer)), or create your own subclass.

Graphics renderers provide memory-efficient management of Core Graphics contexts. Core Graphics contexts represent the drawing environment and backing store for 2D Graphics. As you reuse a graphics renderer, it in turn reuses Core Graphics contexts.

### Subclassing notes

You can’t use [`UIGraphicsRenderer`](/documentation/UIKit/UIGraphicsRenderer) directly, but if the concrete subclasses ([`UIGraphicsPDFRenderer`](/documentation/UIKit/UIGraphicsPDFRenderer) and [`UIGraphicsImageRenderer`](/documentation/UIKit/UIGraphicsImageRenderer)) don’t provide the functionality you require, you can create your own subclass.

Consider creating a subclass any time you need to create multiple Core Graphics contexts, each with the same dimensions and attributes, and one of the concrete subclasses ([`UIGraphicsPDFRenderer`](/documentation/UIKit/UIGraphicsPDFRenderer) or [`UIGraphicsImageRenderer`](/documentation/UIKit/UIGraphicsImageRenderer)) doesn’t provide the functionality you require.

To create a subclass of [`UIGraphicsRenderer`](/documentation/UIKit/UIGraphicsRenderer), first import the appropriate submodule or header, as shown in the following code.

```objc
#import <UIKit/UIGraphicsRendererSubclass.h>
```

A graphics renderer manages a pool of Core Graphics contexts that are reused with repeated uses of the renderer. The renderer creates these <doc://com.apple.documentation/documentation/CoreGraphics/CGContext> objects using the [`context(with:)`](/documentation/UIKit/UIGraphicsRenderer/context(with:)) class method, and then wraps each of them in an instance of the class returned by the [`rendererContextClass()`](/documentation/UIKit/UIGraphicsRenderer/rendererContextClass()) class method. You must therefore override these two methods in your graphics renderer subclass.

To perform drawing actions on a Core Graphics context, call the [`runDrawingActions(_:completionActions:)`](/documentation/UIKit/UIGraphicsRenderer/runDrawingActions(_:completionActions:)) method, providing two blocks. Both of these blocks have a [`UIGraphicsRendererContext`](/documentation/UIKit/UIGraphicsRendererContext) argument, providing access to a Core Graphics context.

It is recommended that you create a public method on your renderer subclass that internally wraps the [`runDrawingActions(_:completionActions:)`](/documentation/UIKit/UIGraphicsRenderer/runDrawingActions(_:completionActions:)) method. This is how the rendering methods operate on the concrete subclasses, for example the [`image(actions:)`](/documentation/UIKit/UIGraphicsImageRenderer/image(actions:)) method on [`UIGraphicsImageRenderer`](/documentation/UIKit/UIGraphicsImageRenderer).

Each time the [`runDrawingActions(_:completionActions:)`](/documentation/UIKit/UIGraphicsRenderer/runDrawingActions(_:completionActions:)) method is called, the renderer calls the [`prepare(_:with:)`](/documentation/UIKit/UIGraphicsRenderer/prepare(_:with:)) method with the <doc://com.apple.documentation/documentation/CoreGraphics/CGContext> and [`UIGraphicsRendererContext`](/documentation/UIKit/UIGraphicsRendererContext) as arguments. Override the [`prepare(_:with:)`](/documentation/UIKit/UIGraphicsRenderer/prepare(_:with:)) method to apply the [`UIGraphicsRendererContext`](/documentation/UIKit/UIGraphicsRendererContext) configuration to the underlying <doc://com.apple.documentation/documentation/CoreGraphics/CGContext> before the renderer invokes the drawing actions.

## Topics

### Initializing a graphics renderer

[`init(bounds:)`](/documentation/UIKit/UIGraphicsRenderer/init(bounds:))

Creates a new graphics renderer with the specified bounds and a default format.

[`init(bounds:format:)`](/documentation/UIKit/UIGraphicsRenderer/init(bounds:format:))

Creates a new graphics renderer with the given bounds and format.

### Configuring the renderer

[`allowsImageOutput`](/documentation/UIKit/UIGraphicsRenderer/allowsImageOutput)

A Boolean value specifying whether the renderer can create output images.

[`format`](/documentation/UIKit/UIGraphicsRenderer/format)

The format used to create the graphics renderer.

### Running the drawing actions

[`runDrawingActions(_:completionActions:)`](/documentation/UIKit/UIGraphicsRenderer/runDrawingActions(_:completionActions:))

Performs drawing actions on a Core Graphics context that the renderer prepares.

[`UIGraphicsDrawingActions`](/documentation/UIKit/UIGraphicsDrawingActions)

A closure that executes a set of drawing instructions that the renderer applies to the Core Graphics context.

### Managing graphics contexts

[`context(with:)`](/documentation/UIKit/UIGraphicsRenderer/context(with:))

Creates a Core Graphics context configured according to the supplied format object.

[`prepare(_:with:)`](/documentation/UIKit/UIGraphicsRenderer/prepare(_:with:))

Applies the configuration specified in the renderer context to the Core Graphics context.

[`rendererContextClass()`](/documentation/UIKit/UIGraphicsRenderer/rendererContextClass())

Specifies the drawing context class used by this graphics renderer.



---

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)