Is there a way to use San Francisco symbols on mac

2020-06-17 05:17发布

问题:

Please see the question title. As far as I can see, it does not support NSImage(systemName: String) syntax when trying to use it on a macOS project. To be specific, I was trying to use it on a toolbar item.

回答1:

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.



回答2:

SF Symbols are unavailable on macOS. From Apple's Human Interface Guidelines:

You can use SF Symbols in apps running in iOS 13 and later, watchOS 6 and later, and tvOS 13 and later.



回答3:

There is no way yet to use SF symbols on macOS. However you can use this extension as a fall back on macOS so your code will run on multiple platforms.

extension Image {
    init(systemName: String) {
        self.init("YOUR FALL BACK IMAGE(s)")
    }
}


回答4:

Important Before use code bellow read this article How to support San Francisco Fonts on old iOS app and macOS

Button(action: {}) {
  Image(systemName: "star")            
}
I make Image for macOS like below

that's how it looks on macOS

And for cut/paste:

import SwiftUI

#if os(macOS)
struct Image: View {
  let symbol: String

  init(systemName: String) {
    self.symbol = [
      "speaker":      "              
                            
标签: macos swiftui