Search code examples
swiftmacoscocoa

How can I increase the NSStatusBar Image size?


I noticed the image size regardless of which image I use it is slitty smaller than the other apps image in macOS menu bar.

This is the code i used in 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")
}

How to make my image size get the same size as other apps?

The result:

enter image description here


Solution

  • The following source code should make the icon larger, but may be too large. You may read about it here: 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