swift - SystemStatusBar statusItem title being cut short on OS X -
i trying display os x application statusitem in system status bar , having success except fact title being cut off. initializing so:
let statusitem = nsstatusbar.systemstatusbar().statusitemwithlength(-1) func applicationdidfinishlaunching(anotification: nsnotification) { let icon = nsimage(named: "statusicon") icon?.template = true statusitem.image = icon statusitem.menu = statusmenu statusitem.title = "this test title" }
the problem statusitem.title
appearing so:
as can see application next mine (istatmenubar) cutting off title application (or similar happening)
if comment out icon statusitem, works , shows entire title when re-add icon cuts off again. there way 2 (icon , title) co exist? have reviewed apple docs , may have missed critical piece explains this.
thanks guys.
one option assign custom view statusbaritem , within view's class override drawrect(dirtyrect: nsrect) e.g.
private var icon:statusmenuview? let bar = nsstatusbar.systemstatusbar() item = bar.statusitemwithlength(-1) self.icon = statusmenuview() item!.view = icon
and statusmenuview might like:
// edited copy & paste 1 of personal projects might missing code class statusmenuview:nsview { private(set) var image: nsimage private let titlestring:nsstring = "really long title..." init() { icon = nsimage(named: "someimage")! let mywidestatusbaritemframe = cgrectmake(0, 0, 180.0, nsstatusbar.systemstatusbar().thickness) super.init(frame.rect) } override func drawrect(dirtyrect: nsrect) { self.item.drawstatusbarbackgroundinrect(dirtyrect, withhighlight: self.isselected) let size = self.image.size let rect = cgrectmake(2, 2, size.width, size.height) self.image.drawinrect(rect) let titlerect = cgrectmake( 2 + size.width, dirtyrect.origin.y, 180.0 - size.width, size.height) self.titlestring.drawinrect(titlerect, withattributes: nil) } }
now, above might change event handling, you'll need handle mousedown in statusmenuview class.
Comments
Post a Comment