Not an easy one. Haven't found a good way to do so, other than changing the interface style for the entire system-wide extras. Mostly, I set it up in the mode I want when I create the interface, and I set it back when it is dismissed. If other peeps have a better solution, I'm all ears.
My code is in SwiftUI, so you might need adapting. I want the light mode on my side, but that's equivalent.
fileprivate static var currentWindowScene: UIWindowScene? {
UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene
}
// Make sur the color picker is not inverted
if let windows = Self.currentWindowScene?.windows {
for window in windows {
if window.windowLevel != .normal && window.windowLevel != .alert && window.windowLevel != .statusBar {
if overriddenWindows[window] == nil {
DispatchQueue.main.async {
overriddenWindows[window] = window.overrideUserInterfaceStyle
}
}
window.overrideUserInterfaceStyle = .light
}
}
}
Elsewhere (on toolPicker first initialization):
toolPicker.overrideUserInterfaceStyle = .light
When the window is closed:
.onDisappear {
if let windows = Self.currentWindowScene?.windows {
for window in windows {
if let overridden = overriddenWindows[window] {
window.overrideUserInterfaceStyle = overridden
}
}
overriddenWindows = .init()
}
}
When the image is drawn:
var result: UIImage?
UITraitCollection(userInterfaceStyle: UIUserInterfaceStyle.light).performAsCurrent {
result = drawing.image(from: CGRect(x: 0, y: 0,
width:zoneSize.width,
height: zoneSize.height),
scale: UIScreen.main.scale)
}
return result