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": "