๐Ÿ“ฆCanvas

Every canvas has a context and a size to work with.

struct HexagonView: View {
    var body: some View {
        // โญ๏ธ canvas
        Canvas { context, size in
            // โญ๏ธ draw text
            context.draw(
                Text("Design+Code"),
                at: CGPoint(x: 100, y: 100)
            )
            // โญ๏ธ draw image
            context.draw(
                Image("Blob 1"),
                in: CGRect(x: 50, y: 150, width: 300, height: 200)
            )
            context.draw(
                Image(systemName: "hexagon"),
                // โญ๏ธ image size relative to parent
                in: CGRect(x: 25, y: 150, width: size.width/4, height: size.height/6)
            )
            // โญ๏ธ fill path
            context.fill(
                Path(ellipseIn: CGRect(x: 10, y: 10, width: 50, height: 50)),
                with: .color(.red)
            )
        }
    }
}

Last updated