CCNStatusItem is a subclass of NSObject to act as a custom view for NSStatusItem. Running on Yosemite it has full support for the class NSStatusBarButton which is provided by NSStatusItem via the button property. Yosemite's dark menu mode will be automatically handled.
It supports a customizable statusItemWindow that will manage any NSViewController instance for presenting the content.
Here is a shot of the included example application:
You can add CCNStatusItem by using CocoaPods. Just add this line to your Podfile:
pod 'CCNStatusItem'
After it's integrated into your project you are just a four-liner away from your (maybe) first NSStatusItem with a custom view and a beautiful looking popover window. A good place to add these lines of code is your AppDelegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
...
[CCNStatusItem presentStatusItemWithImage:[NSImage imageNamed:@"statusbar-icon"]
contentViewController:[[ContentViewController alloc] initWithNibName:NSStringFromClass([ContentViewController class]) bundle:nil]];
...
}That's all! You will have some options to change the design of this statusItem popover window using CCNStatusItemWindowDesign. In the example above internally CCNStatusItem uses [CCNStatusItemWindowDesign defaultDesign] to set a default design. The next example will show you how to change the design of your statusItem popover window:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
...
CCNStatusItemWindowAppearance *appearance = [CCNStatusItemWindowAppearance defaultAppearance];
style.backgroundColor = [NSColor colorWithCalibratedRed:0.577 green:0.818 blue:0.130 alpha:1.000];
style.cornerRadius = 115.0;
appearance.presentationTransition = CCNPresentationTransitionSlideAndFade;
[CCNStatusItem setWindowAppearance:appearance];
[CCNStatusItem presentStatusItemWithImage:[NSImage imageNamed:@"statusbar-icon"]
contentViewController:[[ContentViewController alloc] initWithNibName:NSStringFromClass([ContentViewController class]) bundle:nil]];
...
}The statusItem window's frame size will be determined automatically by calling preferedContentSize on the contentViewController. So you shouldn't forget to set it to a reasonable value. Using XIB's for building the content a good war to do so is returning:
- (CGSize)preferredContentSize {
return self.view.frame.size;
}
CCNStatusItem was written using ARC and "modern" Objective-C 2. At the moment it has only support for OS X 10.10 Yosemite.
The code is provided as-is, and it is far off being complete or free of bugs. If you like this component feel free to support it. Make changes related to your needs, extend it or just use it in your own project. Pull-Requests and Feedbacks are very welcome. Just contact me at [phranck@cocoanaut.com](mailto:phranck@cocoanaut.com?Subject=[CCNStatusItem] Your component on Github) or send me a ping on Twitter @TheCocoaNaut.
The complete documentation you will find on CocoaDocs.
This software is published under the MIT License.


