One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

Canvas

struct · iOS 15.0+ · SDK 27.1

nonisolated struct Canvas<Symbols> where Symbols : View

A view type that supports immediate mode drawing. Use a canvas to draw rich and dynamic 2D graphics inside a SwiftUI view. The canvas passes a ``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 ``GraphicsContext/stroke(_:with:lineWidth:)`` command to draw a ``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 ellipse inside a blue rectangle.](Canvas-1) 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:)`` 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``. 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.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Canvas.renderer

The iOS SDK compiler rejected this binding: 'inout' may only be used on parameters

Canvas.init(opaque:colorMode:rendersAsynchronously:renderer:symbols:)

callback cannot propagate synchronous failure

All SwiftUICore types →