TabsVC.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // TabsVC.swift
  3. // KMComponentLibrary
  4. //
  5. // Created by Niehaoyu on 2024/9/11.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class TabsVC: NSViewController {
  10. @IBOutlet weak var tabsItem: ComponentTabsItem!
  11. @IBOutlet weak var tabsView: ComponentTabs!
  12. @IBOutlet weak var typeBox: NSComboBox!
  13. @IBOutlet weak var showIconBtn: NSButton!
  14. @IBOutlet weak var itemWidthConst: NSLayoutConstraint!
  15. @IBOutlet weak var itemHeightConst: NSLayoutConstraint!
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. // Do view setup here.
  19. self.typeBox.selectItem(at: 0)
  20. self.reloadData()
  21. }
  22. func reloadData() {
  23. var type: ComponentTabsType = .fill
  24. if typeBox.indexOfSelectedItem == 0 {
  25. type = .underline_Center
  26. } else if typeBox.indexOfSelectedItem == 1 {
  27. type = .underline_Fill
  28. } else if typeBox.indexOfSelectedItem == 2 {
  29. type = .onlyText
  30. }
  31. //tabsItem
  32. let properties: ComponentTabsProperty = ComponentTabsProperty(tabsType: type, state: .normal, showIcon: self.showIconBtn.state == .on, title: "Tab Title Item")
  33. self.tabsItem.properties = properties
  34. self.itemWidthConst.constant = self.tabsItem.properties.propertyInfo.viewWidth
  35. //Tabs
  36. var itemArr: [ComponentTabsProperty] = []
  37. for i in 0...2 {
  38. let property = ComponentTabsProperty(tabsType: type, state: .normal, showIcon: self.showIconBtn.state == .on, title: "Tab Title")
  39. if i == 0 {
  40. property.state = .pressed
  41. }
  42. itemArr.append(property)
  43. }
  44. self.tabsView.updateItemProperty(itemArr)
  45. }
  46. @IBAction func chooseAction(_ sender: Any) {
  47. self.reloadData()
  48. }
  49. }