NavigationDemoVC.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // NavigationDemoVC.swift
  3. // KMComponentLibraryDemo
  4. //
  5. // Created by wanjun on 2024/8/2.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class NavigationDemoVC: NSViewController {
  10. @IBOutlet weak var navigationView: ComponentNavBarItem!
  11. @IBOutlet weak var showIcon: NSButton!
  12. @IBOutlet weak var textField: NSTextField!
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. // Do view setup here.
  16. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: textField)
  17. self.reloadData()
  18. }
  19. func reloadData() {
  20. let property = ComponentNavbarItemProperty(state: .normal,
  21. text: self.textField.stringValue,
  22. iconImage: self.showIcon.state == .on ? NSImage(named: "KMImageNameHomePDFToExcel") : nil)
  23. property.isDisabled = true
  24. navigationView.properties = property
  25. navigationView.setTarget(self, action: #selector(butotnAction_test(_:)))
  26. }
  27. // MARK: Action
  28. @IBAction func showIconAction(_ sender: NSButton) {
  29. self.reloadData()
  30. }
  31. @IBAction func butotnAction_test(_ sender: NSButton) {
  32. }
  33. // MARK: Notification
  34. @objc func textFieldDidEndEditingNotification(_ notification: Notification) {
  35. if textField.stringValue.isEmpty == true {
  36. return
  37. }
  38. self.reloadData()
  39. }
  40. }