<!--
{
  "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/Canvas",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6CanvasV"
  },
  "title" : "Canvas"
}
-->

# Canvas

A view type that supports immediate mode drawing.

```
nonisolated struct Canvas<Symbols> where Symbols : View
```

## Overview

Use a canvas to draw rich and dynamic 2D graphics inside a SwiftUI view.
The canvas passes a [`GraphicsContext`](/documentation/SwiftUI/GraphicsContext) to the closure that you use
to perform immediate mode drawing operations. The canvas also passes a
<doc://com.apple.documentation/documentation/CoreFoundation/CGSize> value
that you can use to customize what you draw. For example, you can use the
context’s [`stroke(_:with:lineWidth:)`](/documentation/SwiftUI/GraphicsContext/stroke(_:with:lineWidth:)) command to draw
a [`Path`](/documentation/SwiftUI/Path) instance:

```
Canvas { context, size in
    context.stroke(
        Path(ellipseIn: CGRect(origin: .zero, size: size)),
        with: .color(.green),
        lineWidth: 4)
}
.frame(width: 300, height: 200)
.border(Color.blue)
```

The example above draws the outline of an ellipse that exactly inscribes
a canvas with a blue border:

![A screenshot of a canvas view that shows the green outline of an](images/com.apple.SwiftUI/Canvas-1~dark@2x.png)

In addition to outlined and filled paths, you can draw images, text, and
complete SwiftUI views. To draw views, use the
[`init(opaque:colorMode:rendersAsynchronously:renderer:symbols:)`](/documentation/SwiftUI/Canvas/init(opaque:colorMode:rendersAsynchronously:renderer:symbols:)) method
to supply views that you can reference from inside the renderer. You can
also add masks, apply filters, perform transforms, control blending, and
more. For information about how to draw, see [`GraphicsContext`](/documentation/SwiftUI/GraphicsContext).

A canvas doesn’t offer interactivity or accessibility for
individual elements, including for views that you pass in as symbols.
However, it might provide better performance for a complex drawing that
involves dynamic data. Use a canvas to improve performance for a drawing
that doesn’t primarily involve text or require interactive elements.

## Topics

### Creating a canvas

[`init(opaque:colorMode:rendersAsynchronously:renderer:)`](/documentation/SwiftUI/Canvas/init(opaque:colorMode:rendersAsynchronously:renderer:))

Creates and configures a canvas.

[`init(opaque:colorMode:rendersAsynchronously:renderer:symbols:)`](/documentation/SwiftUI/Canvas/init(opaque:colorMode:rendersAsynchronously:renderer:symbols:))

Creates and configures a canvas that you supply with renderable
child views.

### Managing opacity and color

[`isOpaque`](/documentation/SwiftUI/Canvas/isOpaque)

A Boolean that indicates whether the canvas is fully opaque.

[`colorMode`](/documentation/SwiftUI/Canvas/colorMode)

The working color space and storage format of the canvas.

### Referencing symbols

[`symbols`](/documentation/SwiftUI/Canvas/symbols)

A view that provides child views that you can use in the drawing
callback.

### Rendering

[`rendersAsynchronously`](/documentation/SwiftUI/Canvas/rendersAsynchronously)

A Boolean that indicates whether the canvas can present its contents
to its parent view asynchronously.

[`renderer`](/documentation/SwiftUI/Canvas/renderer)

The drawing callback that you use to draw into the canvas.



---

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)
