創(chuàng)建狀態(tài)欄圖標(biāo)
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//獲取系統(tǒng)單例NSStatusBar對(duì)象
self.statusBar= [NSStatusBarsystemStatusBar];
//創(chuàng)建固定寬度的NSStatusItem
_statusItem = [self.statusBar statusItemWithLength:NSVariableStatusItemLength];
[_statusItem.buttonsetTarget:self];
[_statusItem.buttonsetAction:@selector(itemAction:)];
_statusItem.button.image = [NSImage imageNamed:@"toplogoIcon"];
}
// 自定義view設(shè)置彈出框內(nèi)容
- (void)itemAction:(NSButton *)button{
NSPopover *popover = [[NSPopover alloc] init];
popover.behavior = NSPopoverBehaviorApplicationDefined;
popover.contentViewController = [NSViewController new];
popover.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];
[popover showRelativeToRect:button.bounds ofView:button preferredEdge:NSRectEdgeMaxY];
}