美文网首页
Mac 开发学习笔记

Mac 开发学习笔记

作者: 东引瓯越 | 来源:发表于2016-02-29 13:22 被阅读394次

    Mac 开发学习笔记

    先说说百度云同步盘的 UI设计 先从 UI 开始

    1. Mac如何开启后台应用(就是在 dock 那个地方 启动应用的时候不显示)?

      点击工程的 Target 设置 Info:
      Application is background only == YES

    2. 在 Mac 状态栏右上角显示的叫做NSStatusItem

      代码块

    
        let statusItem: NSStatusItem = NSStatusBar.systemStatusBar().statusItemWithLength(NSSquareStatusItemLength)
        let mainMenu: NSMenu = NSMenu()
        
        let item1 = NSMenuItem(title: "测试1", action: "test1:", keyEquivalent: "")
        let item2 = NSMenuItem(title: "测试2", action: "test2", keyEquivalent: "")
        let item3 = NSMenuItem(title: "测试3", action: "test3", keyEquivalent: "")
        let item4 = NSMenuItem(title: "测试4", action: "test4", keyEquivalent: "")
        let item5 = NSMenuItem(title: "测试5", action: "test5", keyEquivalent: "")
    
        
    
        func applicationDidFinishLaunching(aNotification: NSNotification) {
            
            mainMenu.delegate = self
            mainMenu.addItem(item1)
            mainMenu.addItem(item2)
            mainMenu.addItem(item3)
            mainMenu.addItem(item4)
            mainMenu.addItem(item5)
            
            statusItem.button?.image = NSImage(named: "status-syncfinished-lep")
            statusItem.menu = mainMenu
            mainMenu.autoenablesItems = true
        }
    
        func applicationWillTerminate(aNotification: NSNotification) {
            // Insert code here to tear down your application
        }
    
    
        
        func test1(sender: NSStatusBarButton) {
            print(__FUNCTION__)
        }
        
        func test2() {
            print(__FUNCTION__)
        }
        func test3() {
            print(__FUNCTION__)
        }
        
        func test4() {
            print(__FUNCTION__)
        }
        
        func test5() {
            print(__FUNCTION__)
        }
        
        
        // MARK: NSMenuDelegate
        
        func menuWillOpen(menu: NSMenu) {
            if menu == mainMenu {
                print(__FUNCTION__)
            }
        }
        ```
        
    

    相关文章

      网友评论

          本文标题:Mac 开发学习笔记

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