我正在尝试将;
用作NSTextField
。
但是它不起作用。
这是我的代码:
NSMenuItem
然后我将其添加到菜单中,如下所示:
class charPoolBoxForMenuItemInstance: NSTextField,NSTextFieldDelegate{
override init(frame: CGRect) {
super.init(frame: frame)
self.delegate = self
}
required init?(coder: NSCoder) {super.init(coder: NSCoder.init())}
override func textDidChange(_ notification: Notification) {
if self.currentEditor()?.selectedRange != nil{UserDefaults.standard.set(self.stringValue, forKey: "charPoolBox")
}
}
}
var charPoolBoxForMenuItem = charPoolBoxForMenuItemInstance.init(string: String.init())
这是灰色的样子:
更新:
let charPoolMenuItem = NSMenuItem()
charPoolMenuItem.title = "Character Pool"
charPoolMenuItem.view = charPoolBoxForMenuItem
charPoolBoxForMenuItem.placeholderString = "Character Pool"
charPoolBoxForMenuItem.frame = CGRect(x: 30, y: 0, width: 400, height: 22)
menuBarMenu.addItem(charPoolMenuItem)
答案 0 :(得分:0)
您还需要操作的目标:
charPoolMenuItem.action = #selector(resetPoolChar)
charPoolMenuItem.target = self