NSStatusBar : macOS系統(tǒng)的頂部導(dǎo)航欄item
@interface AppDelegate (){
NSStatusItem * statusItem;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
/* 初始化 */
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
/* 設(shè)置NSImage * /
[statusItem.button setImage:[NSImage imageNamed:@"statusItem"]];
/* 設(shè)置點擊響應(yīng)事件 */
statusItem.action = @selector(touchStatusItem:);
}
NSPopover : pop視圖
@interface AppDelegate (){
NSPopover * popover;
}
-(void)touchStatusItem:(NSStatusBarButton *)button{
/* 初始化 */
popover = [[NSPopover alloc]init];
/* 設(shè)置動畫 */
popover.behavior = NSPopoverBehaviorTransient;
/* 設(shè)置外觀 */
popover.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];
/* 設(shè)置展示視圖 */
popover.contentViewController = [[PopViewController alloc]initWithNibName:@"PopViewController" bundle:nil];
/* 設(shè)置展示方位 */
[popover showRelativeToRect:button.bounds ofView:button preferredEdge:NSRectEdgeMaxY];
}
效果圖
NSStatusBar + NSPopover效果圖