Search code examples
iconsswiftuisystem

Use system icon in SwiftUI with macOS as button


I like to use build-in icons for my buttons in SwiftUI, including a rectangle around the image. Simply like an ordinary button with a system icon.

But how can I use them? I can copy them as independend graphics in my project and then use

Image("MyIconName")

but I like to access them without making individual copy, like

Image( NSImage(NSImageNamePathTemplate) )

Any idea?

BTW: This does not belong to not support iOS icons, because NSImage offers these directly in macOS.


Solution

  • Here it is

    Image(nsImage: NSImage(named: NSImage.pathTemplateName)!)