Programmatically adding glyphs (delete key, backspace, space, etc.) to the menu item

It used to be that in Carbon you could use SetMenuItemKeyGlyph. What is the alternative under 10.6? Do I need to use undocumented kindness or ...?

thank

+3
source share
1 answer

Use -[NSMenuItem setKeyEquivalent:]and assign it the NSStringcharacter you want to use. NSMenuItemwill handle the translation @" "in Spacefor you etc.

Delete key (aka "Backspace". This is the usual delete button on the keyboard):

[myMenuItem setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x08]];

Direct delete key ("del" key):

[myMenuItem setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x7f]];

space:

[myMenuItem setKeyEquivalent:@" "];

Tab:

[myMenuItem setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x09]];
+6
source

Source: https://habr.com/ru/post/1755192/


All Articles