I have a NSToolbarItem
that uses a view similar to the Xcode status view. It currently has no label, but I can't figure out a way to draw into the area where the item label would normally be drawn. I would like the view to extend into that area just as the Xcode status view does. I know the very bottom portion of pixels of NSToolbar
is out of bounds, but I have seen other applications draw into the label area. Any ideas?
Edit: For clarification, this is the status view I'm referring to in Xcode:
I want the bounds of my view to extend past the label area of the toolbar just as the view in Xcode does.
This code installs a window floating on top of the toolbar.
You have to subclass NSToolbarItem:
Create a toolbar:
Use NSToolbarDelegate to fill your toolbar with items:
The lcd view should be (in this case) 32 points high before you hand it over to the toolbar item. If it's bigger, the toolbar will be too high.
The Xcode status view is actually a separate window floating over the toolbar. (This is easily tested: press ⇧⌘4 and press space to take a screen shot of a window, and hover the mouse over it.)
The Xcode status view is not an
NSToolbarItem
is a customNSView
inserted in theNSToolbar
.The iTunes-XCode-LCD that extends in the label area is not a
NSToolbarItem
. SinceNSToolbar
isn't aNSView
, you cannot add a subview to aNSToolbar
instance. But you can add a custom view directly in the window frame, that can be accessed through thecontentView.superview
property path of theNSWindow
instance!I.e. make your own subclass of NSWindowController and put some code like this in the 'windowDidLoad' method:
This code will not work in Lion's full-screen mode, since the frame window isn't drawn when in fullscreen. To fix this, the view can be moved in a floating window, child of the main one (just check the NSWindow addChildWindow:ordered: method).
If you log
You will get
NSToolbarView doesn't autoresize it's subviews so you have issues with centering it. And
[self.window.contentView superview]
doesn't contain the toolbarview when full screen.You can add the view you want in the center of the toolbar to the
[self.window.contentView superview]
when not in fullscreen and position it properly. It will autoresize and stay centered. When switching to full screen remove it from[self.window.contentView superview]
and add it to NSToolbarView in the center that way it stays in the toolbar and it also moves down with the toolbar when you reveal the status bar.You can get the toolbar view by iterating thru the subviews or with a private method
Update: I did a little more digging with the debugger and I found out that this is what Xcode does. At least while not in full screen.
And the activity view is gone :)
While in full screen however. It doesn't add it to NSToolbarView it adds it to NSNextStepFrame which is NSToolbarView's superview. The toolbar is not contained in the window's contentview superview when in full screen. I think it has something to do with full screen behavior and spaces.