Using PencilKit in dark mode results in wrong color
Asked Answered
C

2

10

When in dark mode, it seems that all the color set in PKInkingTool are reversed in brightness. If I choose a bright red I got a dark red, and vice versa.

For example, if I use UIColorPickerViewController to select a color:

PKInkingTool(.pencil, color:color, width:10)

The color that shows up in PKCanvasView is not the correct color. The only way that seems to work is not to support dark mode.

 overrideUserInterfaceStyle = .light

Is there a way to get PencilKit to use the correct color rather than convert color automatically?

Cartelize answered 7/7, 2020 at 6:24 Comment(4)
I think the entire idea for dark mode support in PencilKit is to let it automatically choose colors that will still look good in dark mode. Those colors will not be the same as in light mode. For example, if you are not in dark mode and you are writing with a black pen on a white background, the pen's color must change or it will not be visible in dark mode, i.e. black on black.Peking
@Peking There's a bug in PKCanvasView. I can reproduce the same bug as reported by the OP. If the app is launched in dark mode, the canvas stays in light mode, and drawing with the "label" color results in the pen drawing in black.Dewyeyed
@BrunoPhilipe what do you mean by "label" color? I'm testing it right now, and if I have my iPad in dark mode and I launch my PencilKit app, the canvas is also in dark mode and the colors adjust as expected. If I switch the iPad to light mode while the app is open, all the colors and the tool picker colors switch as expected so the "white" color option becomes a "black" color option.Peking
I know this is an older post, but I have the same error on my iPad and it's driving me nuts. This really seems like bug, when using UIColor.label in dark mode, the pen draws in black (I am creating a custom PencilTool). Did you find a workaround? I can not explicitly use black or white as the colours (obviously) do not change automatically. the only workaround that seems to work is tu use separatorColor instead of label. It is lighter but at least it automatically adapts.Aurie
A
2

The following works regardless of which mode the app starts in:

let color = PKInkingTool.convertColor(.white, from: .light, to: .dark)
let tool = PKInkingTool(.pen, color: color, width: CGFloat(width.rawValue))

The trick is to use PKInkingTool.convertColor instead of the dynamic system colors.

Aggress answered 6/3, 2023 at 2:14 Comment(0)
B
1

You can use 'colorUserInterfaceStyle' for 'PKToolPicker' but in that case if you want to save the drawn part you might have to concern.

colorUserInterfaceStyle = .light
Bonze answered 20/8, 2022 at 10:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.