Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use SF Symbols in macOS SwiftUI development?

Tags:

macos

swiftui

SF Symbols provides a set of over 2,400 consistent, highly configurable symbols you can use in your app. Apple designed SF Symbols to integrate seamlessly with the San Francisco system font, so the symbols automatically ensure optical vertical alignment with text in all weights and sizes.

https://developer.apple.com/design/human-interface-guidelines/sf-symbols/overview/

As far as I can see, macOS does not support NSImage(systemName: String) syntax when trying to use SF Symbols in a macOS project.

To be specific, I was trying to use an SF Symbol glyph on a toolbar item.

like image 353
fankibiber Avatar asked Sep 24 '19 10:09

fankibiber


People also ask

How do I use the SF symbol in SwiftUI?

SwiftUI uses the systemName parameter for SF Symbol lookup. Keep in mind that you can use string interpolation to show an SF Symbol as the part of any text. Another SwiftUI view that plays well with SF Symbols is Label. The Label view contains both text and an image and shows them according to the current context.

Can I use SF Symbols on my website?

You are not able to use this icons on the websites as license of SF symbols do not allow use those symbols externally than apple's products.


2 Answers

SF Symbols is not supported on macOS (yet)

But you can download the SF Symbols App and export the symbols you need as stand-alone images.

like image 34
vadian Avatar answered Sep 19 '22 10:09

vadian


SF Symbol are now available with macOS 11.

SF Symbols are available in iOS 13 and later, macOS 11 and later, watchOS 6 and later, and tvOS 13 and later.

Here is how you use it:

NSImage(systemSymbolName: "hammer", accessibilityDescription: nil)

If you want to support macOS 10.15 and below you have to use the SF Symbols Mac app and export the symbol as SVG and import it back to an asset file in your Xcode project. You can get the app from here.

like image 78
Daniel Avatar answered Sep 18 '22 10:09

Daniel