swiftmacosswiftuinscolor

Swift macOS convert Color to NSColor


I have a Color taken from the asset, I need to convert it to NSColor.

Color("backgroundTheme").opacity(0.3)

How can I do?


Solution

  • NSColor already have a Color init. You can use it like

    NSColor(Color("backgroundTheme")).withAlphaComponent(0.3)
    

    Or you can get color by name like this

    NSColor(named: "backgroundTheme")?.withAlphaComponent(0.3)