美文网首页
macOS创建系统顶部栏Icon图标及交互

macOS创建系统顶部栏Icon图标及交互

作者: Living_元宝儿 | 来源:发表于2023-07-16 10:52 被阅读0次

    创建状态栏图标

    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    
        //获取系统单例NSStatusBar对象
    
            self.statusBar= [NSStatusBarsystemStatusBar];
    
            //创建固定宽度的NSStatusItem
    
            _statusItem = [self.statusBar statusItemWithLength:NSVariableStatusItemLength];
    
            [_statusItem.buttonsetTarget:self];
    
            [_statusItem.buttonsetAction:@selector(itemAction:)];
    
            _statusItem.button.image = [NSImage imageNamed:@"toplogoIcon"];
    
    }
    
    // 自定义view设置弹出框内容
    - (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];
    }
    

    相关文章

      网友评论

          本文标题:macOS创建系统顶部栏Icon图标及交互

          本文链接:https://www.haomeiwen.com/subject/yaaiudtx.html