ButtonDemoVC.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // ButtonDemoVC.swift
  3. // KMComponentLibraryDemo
  4. //
  5. // Created by wanjun on 2024/8/2.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class ButtonDemoVC: NSViewController {
  10. @IBOutlet weak var componentView: ComponentButton!
  11. @IBOutlet weak var typeComboBox: NSComboBox!
  12. @IBOutlet weak var sizeComboBox: NSComboBox!
  13. @IBOutlet weak var disabledButton: NSButton!
  14. @IBOutlet weak var onlyIconButton: NSButton!
  15. @IBOutlet weak var showLeftIconButton: NSButton!
  16. @IBOutlet weak var showRightIconButton: NSButton!
  17. @IBOutlet weak var viewHeight: NSLayoutConstraint!
  18. @IBOutlet weak var viewWidth: NSLayoutConstraint!
  19. @IBOutlet weak var letfBox: NSBox!
  20. let properties_Buttons: ComponentButtonProperty = ComponentButtonProperty.init(type: .primary, size: .xl, state: .normal, onlyIcon: false, showLeftIcon: false, showRightIcon: false, buttonText: "KDAN Mobile")
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. // Do view setup here.
  24. componentView.properties = properties_Buttons
  25. componentView.setTarget(self, action: #selector(butotnAction_test(_:)))
  26. self.sizeComboBox.selectItem(at: 0)
  27. self.reloadData()
  28. }
  29. func refreshViewUI() {
  30. self.viewHeight.constant = self.componentView.properties.propertyInfo.viewHeight
  31. self.viewWidth.constant = self.componentView.properties.propertyInfo.viewWidth
  32. self.componentView.reloadData()
  33. }
  34. func reloadData() {
  35. if let type = componentButtonType(rawValue: self.typeComboBox.indexOfSelectedItem) {
  36. properties_Buttons.type = type
  37. }
  38. if let size = ComponentSize(rawValue: self.sizeComboBox.indexOfSelectedItem) {
  39. properties_Buttons.size = size
  40. }
  41. properties_Buttons.isDisabled = self.disabledButton.state == .on
  42. properties_Buttons.onlyIcon = self.onlyIconButton.state == .on
  43. properties_Buttons.showLeftIcon = self.showLeftIconButton.state == .on
  44. properties_Buttons.showRightIcon = self.showRightIconButton.state == .on
  45. if self.onlyIconButton.state == .on {
  46. self.showLeftIconButton.isEnabled = false
  47. self.showRightIconButton.isEnabled = false
  48. } else {
  49. self.showLeftIconButton.isEnabled = true
  50. self.showRightIconButton.isEnabled = true
  51. }
  52. componentView.properties = properties_Buttons
  53. self.refreshViewUI()
  54. }
  55. // MARK: Action
  56. @IBAction func typeAction(_ sender: NSComboBox) {
  57. self.reloadData()
  58. }
  59. @IBAction func sizeAction(_ sender: NSComboBox) {
  60. self.reloadData()
  61. }
  62. @IBAction func stateAction(_ sender: NSButton) {
  63. self.reloadData()
  64. }
  65. @IBAction func onlyIconAction(_ sender: NSButton) {
  66. self.reloadData()
  67. }
  68. @IBAction func showLeftIconAction(_ sender: NSButton) {
  69. self.reloadData()
  70. }
  71. @IBAction func showRightIconAction(_ sender: NSButton) {
  72. self.reloadData()
  73. }
  74. @IBAction func butotnAction_test(_ sender: NSButton) {
  75. }
  76. }