Skip to main content

Direktes Zeichnen auf der Oberfläche (Canvas)

In diesem einfachen Beispiel wird ein blauer Kreis direkt auf die Oberfläche gezeichnet.

import SwiftUI

struct ContentView: View {
    var body: some View {
        Canvas { context, size in
            // Draw a circle in the center
            let center = CGPoint(x: size.width / 2, y: size.height / 2)
            let circle = Path { path in
                path.addArc(center: center, radius: 50, startAngle: .zero, endAngle: .degrees(360), clockwise: false)
            }
            context.fill(circle, with: .color(.blue))
        }
        .frame(width: 200, height: 200)
    }
}