nsmenuitem

Cocoa Key Equivalent in Menu is not working

孤街浪徒 提交于 2021-02-10 05:51:53
问题 I have created a NSStatusItem and I have assigned two key equivalents within interface builder (Xcode 4.0). These are for the preference menu cmd-, and the quit option cmd-q. Both of these will work when the Menu is highlighted/open but will not work otherwise even if the application is the foremost. Any ideas on why this is happening or how I can change this? 回答1: The operating system passes key events that it doesn't handle to the front application, which compares them to any key

Cocoa Key Equivalent in Menu is not working

Deadly 提交于 2021-02-10 05:51:51
问题 I have created a NSStatusItem and I have assigned two key equivalents within interface builder (Xcode 4.0). These are for the preference menu cmd-, and the quit option cmd-q. Both of these will work when the Menu is highlighted/open but will not work otherwise even if the application is the foremost. Any ideas on why this is happening or how I can change this? 回答1: The operating system passes key events that it doesn't handle to the front application, which compares them to any key

NSMenuItem with custom view disappears while scrolling

五迷三道 提交于 2021-01-29 07:27:11
问题 I implement a NSMenu with NSMenuItem and set custom view to it. When menu is scrollable, mouse hovering on ▼ button to scroll will cause some menuItem disappear (or not draw correctly). Hope someone give me some help. I will appreciate that. Here's video about this issue: https://streamable.com/obrbon Here's my code: private func setupMenuItemView(_ menu: NSMenu) { let menuItemHeight: CGFloat = 20 let menuWidth = frame.width let textFieldPadding: CGFloat = 10 for menuItem in menu.items {

NSMenuItem with attributedTitle containing an NSFont object draws the title with baseline shift

最后都变了- 提交于 2021-01-27 19:31:06
问题 I'm tying to create an NSPopUpButton with the list of fonts available in the system. Seemed pretty obvious task but I've failed. I guess, I'm missing something so obvious that I've completely forgot about it. The code is pretty straight: let button = NSPopUpButton() button.menu = NSMenu() NSFontManager.shared.availableFonts.forEach { fontNameString in let item = NSMenuItem() let font = NSFont(name: fontNameString, size: 14)! let attrs: [NSAttributedString.Key: Any] = [.font: font] item

validateMenuItem or menuWillOpen not called for NSMenu

早过忘川 提交于 2020-12-06 07:27:47
问题 My Mac app has an NSMenu whose delegate functions validateMenuItem and menuWillOpen are never called. So far none of the solutions online have helped. It seems like I'm doing everything right: The menu item's selectors are in the same class. The class managing it inherits from NSMenuDelegate I suppose the best way to describe my problem is to post the relevant code. Any help would be appreciated. import Cocoa class UIManager: NSObject, NSMenuDelegate { var statusBarItem = NSStatusBar.system()