Search code examples
swiftnsmenuitem

Swift OSX Change color of NSMenuItem Title


How do I add a label to NSMenuItem that is disabled but not greyed out.

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

enter image description here


Solution

  • Try this:

    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