swift 如何增加NSStatusBar图像大小?

wfsdck30  于 12个月前  发布在  Swift
关注(0)|答案(1)|浏览(102)

我注意到图像大小,无论我使用哪种图像,它都比macOS菜单栏中的其他应用程序图像小得多。
这是我在可可中使用的代码:

private lazy var statusItem: NSStatusItem = NSStatusItem()

 statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
        
if let button = statusItem.button {
    button.image = NSImage(systemSymbolName: "wifi", accessibilityDescription: "1")
}

如何使我的图像大小与其他应用程序的大小相同?
结果:

8yparm6h

8yparm6h1#

下面的源代码应该使图标变大,但可能太大了。你可以在这里读到:NSImageSymbolConfiguration

// globals at top of AppDelegate
var statusItem: NSStatusItem!
var image: NSImage!

// Then in func applicationDidFinishLaunching()
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
if let button = statusItem.button {
   image = NSImage(systemSymbolName: "wifi", accessibilityDescription: "1");
   let config = NSImage.SymbolConfiguration(scale: .large)
   button.image = image.withSymbolConfiguration(config)
}

相关问题