iOS PencilKit Draw shapes programmatically
Asked Answered
S

2

9

I'm trying to figure out how to modify the PKDrawing property from PKCanvasView to add some shapes like circles or at least add a line however PKDrawing is an opaque type so there is not too much to do.

Is there any workaround to create shapes or lines on a PKCanvasView ?

Sellers answered 21/10, 2019 at 15:28 Comment(1)
I have been searching high and low for an answer to this. From what I can tell you cannot programmatically modify the data in a PKDrawing objectSpectroradiometer
L
3

You can now

yourPKCanvasView.drawing = PKDrawing(strokes: yourPKStrokes)

Full example: https://developer.apple.com/documentation/pencilkit/inspecting_modifying_and_constructing_pencilkit_drawings

Leucine answered 8/1, 2021 at 20:44 Comment(0)
C
1

If you're looking to create the drawing 100% programmatically, from raw CGPoints, instead of from a predefined asset like in Apple's examples, see https://mcmap.net/q/1319122/-how-do-i-create-a-pkdrawing-programmatically-from-cgpoints

Convertible answered 8/12, 2021 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.