// // NavigationDemoVC.swift // KMComponentLibraryDemo // // Created by wanjun on 2024/8/2. // import Cocoa import KMComponentLibrary class NavigationDemoVC: NSViewController { @IBOutlet weak var navigationView: ComponentNavBarItem! @IBOutlet weak var showIcon: NSButton! @IBOutlet weak var textField: NSTextField! override func viewDidLoad() { super.viewDidLoad() // Do view setup here. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: textField) self.reloadData() } func reloadData() { let property = ComponentNavbarItemProperty(state: .normal, text: self.textField.stringValue, iconImage: self.showIcon.state == .on ? NSImage(named: "KMImageNameHomePDFToExcel") : nil) property.isDisabled = true navigationView.properties = property navigationView.setTarget(self, action: #selector(butotnAction_test(_:))) } // MARK: Action @IBAction func showIconAction(_ sender: NSButton) { self.reloadData() } @IBAction func butotnAction_test(_ sender: NSButton) { } // MARK: Notification @objc func textFieldDidEndEditingNotification(_ notification: Notification) { if textField.stringValue.isEmpty == true { return } self.reloadData() } }