Skip to content

Instantly share code, notes, and snippets.

@SLIB53
Created December 12, 2023 19:08
Show Gist options
  • Save SLIB53/43761b997871bfc610b7264ce7374bec to your computer and use it in GitHub Desktop.
Save SLIB53/43761b997871bfc610b7264ce7374bec to your computer and use it in GitHub Desktop.
PencilKit sample
//
// ContentView.swift
// Drawing
//
// Created by Akil Krishnan on 12/5/23.
//
import SwiftUI
import PencilKit
struct ContentView: View {
var body: some View {
PencilView()
}
}
struct PencilView: UIViewRepresentable {
@State var canvasView = PKCanvasView()
@State var toolPicker = PKToolPicker()
func makeUIView(context: Context) -> PKCanvasView {
canvasView.contentSize = CGSize(
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height
)
canvasView.backgroundColor = .clear
canvasView.isScrollEnabled = false
toolPicker.setVisible(true, forFirstResponder: canvasView)
toolPicker.addObserver(canvasView)
canvasView.becomeFirstResponder()
return canvasView
}
func updateUIView(_ uiView: PKCanvasView, context: Context) {}
}
#Preview {
ContentView()
}
//
// DrawingApp.swift
// Drawing
//
// Created by Akil Krishnan on 12/5/23.
//
import SwiftUI
@main
struct DrawingApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.statusBarHidden(true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment