SegmentedVC.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // SegmentedVC.swift
  3. // KMComponentLibrary
  4. //
  5. // Created by Niehaoyu on 2024/9/9.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class SegmentedVC: NSViewController {
  10. @IBOutlet weak var segmented: ComponentSegmented!
  11. @IBOutlet weak var sizeBox: NSComboBox!
  12. @IBOutlet weak var countBox: NSComboBox!
  13. @IBOutlet weak var segmentedheightConst: NSLayoutConstraint!
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do view setup here.
  17. self.reloadData()
  18. }
  19. func reloadData() {
  20. var size: ComponentSize = .m
  21. self.segmentedheightConst.constant = 32
  22. if self.sizeBox.indexOfSelectedItem == 1 {
  23. size = .s
  24. self.segmentedheightConst.constant = 24
  25. }
  26. var count = 2
  27. if self.countBox.indexOfSelectedItem == 0 {
  28. count = 2
  29. } else if self.countBox.indexOfSelectedItem == 1 {
  30. count = 3
  31. } else if self.countBox.indexOfSelectedItem == 2 {
  32. count = 4
  33. }
  34. var itemArr: [ComponentSegmentedProperty] = []
  35. for i in 0...count-1 {
  36. let property = ComponentSegmentedProperty(size: size, active: false, iconImage: NSImage(named: ""), iconImage_active: NSImage(named: ""))
  37. if i == 0 {
  38. property.active = true
  39. }
  40. itemArr.append(property)
  41. }
  42. self.segmented.updateItemProperty(itemArr)
  43. }
  44. @IBAction func boxAction(_ sender: Any) {
  45. self.reloadData()
  46. }
  47. }