123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- //
- // ButtonDemoVC.swift
- // KMComponentLibraryDemo
- //
- // Created by wanjun on 2024/8/2.
- //
- import Cocoa
- import KMComponentLibrary
- class ButtonDemoVC: NSViewController {
-
- @IBOutlet weak var componentView: ComponentButton!
-
- @IBOutlet weak var typeComboBox: NSComboBox!
- @IBOutlet weak var sizeComboBox: NSComboBox!
- @IBOutlet weak var disabledButton: NSButton!
- @IBOutlet weak var onlyIconButton: NSButton!
- @IBOutlet weak var showLeftIconButton: NSButton!
- @IBOutlet weak var showRightIconButton: NSButton!
-
- @IBOutlet weak var viewHeight: NSLayoutConstraint!
- @IBOutlet weak var viewWidth: NSLayoutConstraint!
-
- @IBOutlet weak var letfBox: NSBox!
-
- let properties_Buttons: ComponentButtonProperty = ComponentButtonProperty.init(type: .primary, size: .xl, state: .normal, onlyIcon: false, showLeftIcon: false, showRightIcon: false, buttonText: "KDAN Mobile")
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- componentView.properties = properties_Buttons
- componentView.setTarget(self, action: #selector(butotnAction_test(_:)))
-
- self.sizeComboBox.selectItem(at: 0)
- self.reloadData()
-
- }
-
- func refreshViewUI() {
- self.viewHeight.constant = self.componentView.properties.propertyInfo.viewHeight
- self.viewWidth.constant = self.componentView.properties.propertyInfo.viewWidth
- self.componentView.reloadData()
-
- }
-
- func reloadData() {
- if let type = componentButtonType(rawValue: self.typeComboBox.indexOfSelectedItem) {
- properties_Buttons.type = type
- }
- if let size = ComponentSize(rawValue: self.sizeComboBox.indexOfSelectedItem) {
- properties_Buttons.size = size
- }
- properties_Buttons.isDisabled = self.disabledButton.state == .on
- properties_Buttons.onlyIcon = self.onlyIconButton.state == .on
- properties_Buttons.showLeftIcon = self.showLeftIconButton.state == .on
- properties_Buttons.showRightIcon = self.showRightIconButton.state == .on
-
- if self.onlyIconButton.state == .on {
- self.showLeftIconButton.isEnabled = false
- self.showRightIconButton.isEnabled = false
- } else {
- self.showLeftIconButton.isEnabled = true
- self.showRightIconButton.isEnabled = true
- }
-
- componentView.properties = properties_Buttons
- self.refreshViewUI()
- }
-
- // MARK: Action
-
- @IBAction func typeAction(_ sender: NSComboBox) {
-
- self.reloadData()
- }
-
- @IBAction func sizeAction(_ sender: NSComboBox) {
- self.reloadData()
- }
-
- @IBAction func stateAction(_ sender: NSButton) {
- self.reloadData()
- }
-
- @IBAction func onlyIconAction(_ sender: NSButton) {
- self.reloadData()
- }
-
- @IBAction func showLeftIconAction(_ sender: NSButton) {
- self.reloadData()
- }
-
- @IBAction func showRightIconAction(_ sender: NSButton) {
- self.reloadData()
- }
-
- @IBAction func butotnAction_test(_ sender: NSButton) {
-
- }
- }
|