Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS PencilKit Draw shapes programmatically

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 ?

like image 373
Santiago Carmona González Avatar asked Oct 21 '19 15:10

Santiago Carmona González


2 Answers

You can now

yourPKCanvasView.drawing = PKDrawing(strokes: yourPKStrokes)

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

like image 74
Sam Avatar answered Oct 20 '22 02:10

Sam


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://stackoverflow.com/a/70274331/4075379

like image 23
Roger Oba Avatar answered Oct 20 '22 03:10

Roger Oba