zoukankan      html  css  js  c++  java
  • 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];
                    }
  • 相关阅读:
    应用程序初次运行数据库配置小程序(Java版)
    (转) 移动站适配rel=alternate PC页和H5页适配标注
    (转)微信收货地址开发分享
    (转)PHP EOF(heredoc)的使用方法
    http-equiv是什么意思(转载)
    jQuery Ajax 实例 ($.ajax、$.post、$.get)
    JSON转string、JSON转Object
    php使用curl来获取远程图片
    include和require的区别
    (转)PHP获取随机数
  • 原文地址:https://www.cnblogs.com/741162830qq/p/5156963.html
Copyright © 2011-2022 走看看