简体   繁体   中英

How to modify individual strokes in PKDrawing? - PencilKit / SwiftUI

I'd like to change the colors of individual strokes in a drawing. Printing PKDrawing().strokes returns an array with multiple PencilKit.PKStroke items and I can remove strokes from the array which reflects on the canvas. However, if I wanted to change the color of the first stroke for example, how would I go about it?

Thanks!

You need to modify ink color of stroke, like

let canvasView = PKCanvasView() // assuming we some this somewhere above

...

if !canvasView.drawing.strokes.isEmpty {
     // set color whichever needed
     canvasView.drawing.strokes[0].ink.color = UIColor.red  // << here !!
}

Tested with Xcode 12.1 / iOS 14.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM