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

# context(with:)

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

```
class func context(with format: UIGraphicsRendererFormat) -> CGContext?
```

## Parameters

`format`

The format object that was either supplied to or created by the graphics renderer at initialization time.

## Return Value

A Core Graphics context configured to represent the attributes in the format object.

## Discussion

Each time the graphics renderer needs to create a new Core Graphics context, it calls this method, providing the format object supplied at initialization time.

You must override this method when you subclass `UIGraphicsRenderer`. Use the provided [`UIGraphicsRendererFormat`](/documentation/UIKit/UIGraphicsRendererFormat) to create and configure a <doc://com.apple.documentation/documentation/CoreGraphics/CGContext> object that is used by the renderer in the drawing routines.

---

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)