0

According to NSColor Document, "Colors created from assets can adapt automatically to system appearance changes". However, I want to manually get its color in specific system appearance. For example, as shown below, I create a color set Color in assets catalog. And I want to use its dark mode color in light mode, maybe some thing like NSColor(named: "Color")!.darkModeVariant.

enter image description here

I think this problem can be summarized as retrieving NSColor from dynamic color (light and dark) to a single color. I know this can be done in iOS UIKit like below, but how can I achieve it in macOS AppKit?

extension UIColor {
    var lightModeVariant: UIColor {
        resolvedColor(with: UITraitCollection(userInterfaceStyle: .light))
    }
    var darkModeVariant: UIColor {
        resolvedColor(with: UITraitCollection(userInterfaceStyle: .dark))
    }
}
Yiming Designer
  • 423
  • 3
  • 10

0 Answers0