OS X 10.10 Yosemite-添加菜单 [英] OS X 10.10 Yosemite - Adding a menulet

查看:86
本文介绍了OS X 10.10 Yosemite-添加菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OSX编程的新手,并且最近启动了OS X 10.10的演示项目.找到了-> http://cocoatutorial.grapewave.com/tag/menulet/很好的教程在OSX状态栏中添加菜单.问题是我的项目正在使用快速语言,并且方法和项目结构/文件有些不同.我想知道是否有人在优胜美地上成功尝试过此方法?谢谢.

I am new to OSX programming and recently started a demo project for OS X 10.10. Found this -> http://cocoatutorial.grapewave.com/tag/menulet/ good tutorial to add menulet in OSX status bar. The problem is My project is using swift language and the methods and project structure/files are somewhat different. I would like to know if anyone has successfully tried this on Yosemite? Thanks.

具体问题是如何替换awakefromnib方法以使用当前的AppDelegate.swift语法?

Specific question would be how do i replace awakefromnib method to work with present AppDelegate.swift syntax?

推荐答案

整个过程就是这个……

class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet var window: NSWindow // Remove this and delete window in IB to remove window
    // ... also, remove MainMenu from IB.
    @IBOutlet var statusMenu: NSMenu
    var statusItem: NSStatusItem? = nil

    func applicationDidFinishLaunching(aNotification: NSNotification?) {
        // Insert code here to initialize your application
    }

    func applicationWillTerminate(aNotification: NSNotification?) {
        // Insert code here to tear down your application
    }

    override func awakeFromNib() {
        self.statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(NSVariableStatusItemLength))
        self.statusItem!.menu = self.statusMenu
        self.statusItem!.title = "Status"
        self.statusItem!.highlightMode = true
    }

    @IBAction func doSomethingWithMenuSelection(sender : AnyObject) {
        println("Action pressed")
    }

}

我只是从您的链接中复制了它,并将其翻译为Swift.它仍然显示一个窗口等,应该删除它很简单... UPDATE 显示了如何...

I just copied it from your link, and translated to Swift. It still shows a window, etc., which should be trivial to remove... UPDATE showed how...

(当然,我正在优胜美地上运行它)

(and of course I'm running it on Yosemite)

这篇关于OS X 10.10 Yosemite-添加菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆