Search code examples
cocoansmenuitemnsmenu

Hide the title of an NSMenuItem, just show its image?


I have an NSMenu (belonging to an NSPopUpButton) where the NSMenuItem all have images set and I'd like them to display only the images, not the titles. I can't unset the titles, though, since they provide keyboard accessibility (and, I think, other accessibility). Is there some way to hide the title, like the image position NSImageOnly for NSButton?


Solution

  • A temporary workaround that doesn't really make me happy:

    Instead of setting the title of the NSMenuItem, set the attributed title to the attributed string of the intended title with the system font in an invisibly-small size, such as 0.01.