문제

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