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?

有帮助吗?

解决方案

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.

其他提示

At least for the first item in the menu, it works fine when done this way:

  1. Instantiate the NSPopUpButton in Interface Builder
  2. Set to type Pull down, style Square, and set an image.
  3. Make the position image only (the second option in the palette)

These settings all pertain to the button part of the control, but it will create a menu with the first item being an image-only menu item. Actually, the title is not set (as evidenced by the placeholder being shown in the title field). This should mean that yo can set the title to nil in case you do it programmatically.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top