Thanks to the PencilKit team at Apple, now it is trivial to spin up a simple Apple Pencil canvas view in an iOS 13 app. This will be helpful for any app that may need pencil input.

Below is a Swift code sample for setting up a pencil canvas along with a tool picker:

import UIKit
import PencilKit

class ViewController: UIViewController {
    // Create the pencil canvas view.
    let canvasView = PKCanvasView(frame: .zero)

    override func viewDidLoad() {
        super.viewDidLoad()

        // Add the pencil canvas on top of the main view.
        canvasView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(canvasView)

        // Fit the the pencil canvas to entire screen.
        NSLayoutConstraint.activate([
            canvasView.topAnchor.constraint(equalTo: view.topAnchor),
            canvasView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            canvasView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            canvasView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        ])
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        // Now show the tool picker.
        guard 
            let window = view.window, 
            let toolPicker = PKToolPicker.shared(for: window) else { return }

        toolPicker.setVisible(true, forFirstResponder: canvasView)
        toolPicker.addObserver(canvasView)
        canvasView.becomeFirstResponder()
    }
}