Swift OSX 更改 NSMenuItem 标题的颜色

Swift OSX Change color of NSMenuItem Title

如何向禁用但未灰显的 NSMenuItem 添加标签。

let addToComputerItem : NSMenuItem = NSMenuItem(title: "\(title)", action: nil, keyEquivalent: "") computerInfoMenu.addItem(addToComputerItem) addToComputerItem.enabled = false

试试这个:

let menu = NSMenuItem(title: "Test", action: #selector(AppDelegate.test), keyEquivalent: "K")

menu.attributedTitle = NSAttributedString(string: "Testinggg", attributes: [NSFontAttributeName: NSFont.systemFontOfSize(20), NSForegroundColorAttributeName: NSColor.redColor()])

mainMenu?.itemAtIndex(0)?.submenu?.addItem(menu)//You can add whichever submenu