开发者

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

开发者 https://www.devze.com 2023-01-07 14:52 出处:网络
开发者_JAVA百科It used to be that in Carbon you could use SetMenuItemKeyGlyph. What\'s the alternative under 10.6? Will I need to use undocumented goodness or...?
开发者_JAVA百科

It used to be that in Carbon you could use SetMenuItemKeyGlyph. What's the alternative under 10.6? Will I need to use undocumented goodness or...?

Thanks


Use -[NSMenuItem setKeyEquivalent:] and give it an NSString of the character you want to be used. NSMenuItem will handle translating @" " into Space for you, etc.

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

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

Forward delete key (The "del" key):

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

Space:

[myMenuItem setKeyEquivalent:@" "];

Tab:

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

精彩评论

暂无评论...
验证码 换一张
取 消