如何为菜单栏项创建动态NSImage?

时间:2016-03-28 22:43:17

标签: xcode swift macos

我想创建包含文本的动态图像,将它们分配到菜单栏项目图标。图像文本将是包含一些数据的字符串。

现在我使用以下代码设置菜单栏项目图标:

    let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(NSVariableStatusItemLength)

    func applicationDidFinishLaunching(aNotification: NSNotification) {

        if let button = statusItem.button {
            button.image = NSImage(named: "icon")
        }
    }

我尝试使用button.title设置文字,但我需要两行文字。

如何创建和分配从模板图像+文本创建的动态图标到菜单栏项?

0 个答案:

没有答案