I'm trying to write two lines of text in the macOS system tray, very much like iStat pro does for the network activity:
I know I have to subclass NSView to do so, but I can't manage to get it working even for one line:
class CustomView:NSView {
override func draw(_ dirtyRect: NSRect) {
let text: NSString = "my string"
let textRect: NSRect = NSMakeRect(0, 0, 100, 20)
text.draw(in: textRect)
}
}
and then:
let statusBar = NSStatusBar.system
statusItem = statusBar.statusItem(withLength: 100)
let view = CustomView()
view.wantsLayer = true
statusItem.button?.addSubview(view)
I've found other threads on stackoverflow:
- OS X Status Bar Application with a title in two lines : It's in objective C and I can not get it working neither
- How to show two row of text in a menu bar app in mac os : explainations are not detailled enough for me unfortunately