• Mac开发 - 使用CCMenu和CCMenuItem添加菜单、右击菜单、Dock菜单


    Mac开发 - 使用CCMenu和CCMenuItem添加菜单、右击菜单、Dock菜单
    1、添加一个Dock右击菜单
            NSMenu *appDockMenu = [[NSMenu alloc] initWithTitle:@"DockMenu"];
    [appDockMenu setAutoenablesItems:NO];
    NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"About" action:@selector(aboutDockAction:) keyEquivalent:@""];
    [newItem setTarget: self];
    [appDockMenu addItem:newItem];
    [newItem release];
    
    - (NSMenu *)applicationDockMenu:(NSApplication *)sender
    {
    return appDockMenu;
    }
    
    2、给一个NSView添加右击菜单
    
    NSMenu* newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Copy"]; 
            NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Copy" action:@selector(copyAction:) keyEquivalent:@""];
            [newItem setEnabled:YES];
            [newItem setTarget:self];
            [newMenu addItem:newItem];
            [newItem release];
            
            [myview setMenu:newMenu];
            [newMenu release];
    
    3、给顶部菜单栏,添加菜单
    
    NSMenu* newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"About"]; 
            NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"About"action:@selector(copyAction:) keyEquivalent:@""];
            [newItem setEnabled:YES];
            [newItem setTarget:self];
            [newMenu addItem:newItem];
            [newItem release];
            [[NSApp mainMenu] insertItem:newItem atIndex:3];
            [newMenu release];
     NSMenu *subMenu = [[NSMenu alloc]init];
    
                for (NSDictionary *dic in folderArray) {
    
                    for (NSString *folderKey in [dic allKeys]) {
    
                        NSDictionary *folderInfo = [dic objectForKey:folderKey];
    
                        NSString *appName = [folderInfo objectForKey:@"APP_NAME"];
    
                        IBDMenuItem* newItem = [[IBDMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle: appName action:@selector(moveToAction:) keyEquivalent:@""];
                        //绑定选择移动到item
                        newItem.tag = folderKey.intValue;
                        //绑定要移动的Item  考虑传值问题
                        newItem.selfIndex = index.integerValue;
                        [newItem setTarget: self];
                        [subMenu insertItem:newItem atIndex:0];
                    }
  • 相关阅读:
    微服务:整合 Spring Cloud Eureka
    java连接oracle数据库时报错ORA-12505
    亲测可用转IntelliJ IDEA 2018.3.4永久激活(破解)
    MyEclipse中打开*.js文件时默认为UTF-8编码格式的设置
    linux yum安装lsof命令
    转:Tomcat 7.0配置SSL的问题及解决办法
    Java实现ping功能的三种方法及Linux的区分
    [linux]文件系统损坏,linux启动时 checking filesystems fail
    redhat7下mysql5.7.12重启电脑后起不来问题
    [转]Linux下彻底卸载mysql详解
  • 原文地址:https://www.cnblogs.com/741162830qq/p/5156963.html
Copyright © 2020-2023  润新知