TooltipVC.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // TooltipVC.swift
  3. // KMComponentLibrary
  4. //
  5. // Created by Niehaoyu on 2024/9/10.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class TooltipVC: NSViewController {
  10. @IBOutlet weak var tooltipItem: ComponentToolTip!
  11. @IBOutlet weak var typeBox: NSComboBox!
  12. @IBOutlet weak var titleField: NSTextField!
  13. @IBOutlet weak var subTitleField: NSTextField!
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do view setup here.
  17. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: titleField)
  18. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: titleField)
  19. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: titleField)
  20. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: subTitleField)
  21. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: subTitleField)
  22. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: subTitleField)
  23. self.typeBox.selectItem(at: 0)
  24. self.reloadData()
  25. }
  26. func reloadData() {
  27. let type: ComponentPositionType = ComponentPositionType(rawValue: self.typeBox.indexOfSelectedItem) ?? .left_Top
  28. //progressItem
  29. let properties: ComponentTooltipProperty = ComponentTooltipProperty(arrowPosition: type,
  30. title: self.titleField.stringValue,
  31. infoString: self.subTitleField.stringValue)
  32. self.tooltipItem.properties = properties
  33. }
  34. @IBAction func typeAction(_ sender: Any) {
  35. self.reloadData()
  36. }
  37. //MARK: - TextNotification
  38. @objc func textFieldDidBeginEditingNotification(_ notification: Notification) {
  39. print("textFieldDidBeginEditingNotification")
  40. }
  41. @objc func textFieldDidChangeNotification(_ notification: Notification) {
  42. print("textFieldDidChangeNotification")
  43. self.reloadData()
  44. }
  45. @objc func textFieldDidEndEditingNotification(_ notification: Notification) {
  46. print("textFieldDidEndEditingNotification")
  47. self.reloadData()
  48. }
  49. }