如何增加 NSStatusBar 图像大小?

How can I increase the NSStatusBar Image size?

提问人:bulletproof software engineer 提问时间:9/6/2023 更新时间:9/10/2023 访问量:101

问:

我注意到,无论我使用哪种图像,图像大小都比 macOS 菜单栏中的其他应用程序图像小一点。

这是我在 cocoa 中使用的代码:

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")
}

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

结果:

enter image description here

Swift macOS

评论

0赞 Gerd K 9/6/2023
你有没有试过用,比如说,?NSStatusItem.variableLength22
0赞 bulletproof software engineer 9/6/2023
是的,但这与问题无关,正如我们可以读到的那样:或者它的意思是长度,但问题与高度有关。顺便说一句,我尝试了你的方式,但没有帮助。withLengthNSStatusItem.variableLength

答:

3赞 apodidae 9/6/2023 #1

以下源代码应使图标变大,但可能太大。您可以在此处阅读有关它的信息: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)
}

enter image description here

评论

0赞 bulletproof software engineer 9/6/2023
我认为它对结果没有尊重。
0赞 apodidae 9/6/2023
它显然更大。请参阅编辑后的答案。