KMCompressCellView.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // KMCompressCellView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/11/26.
  6. //
  7. import Cocoa
  8. class KMCompressCellView: NSTableCellView {
  9. var backGroundView: NSView = NSView()
  10. var label: NSTextField = NSTextField(labelWithString: "")
  11. var selectedLabel: NSTextField = NSTextField(labelWithString: "")
  12. var button = KMImageTitleButton()
  13. private var mySelected = false
  14. var isSelected: Bool {
  15. get {
  16. return mySelected
  17. }
  18. set {
  19. mySelected = newValue
  20. if newValue {
  21. selectedLabel.isHidden = false
  22. } else {
  23. selectedLabel.isHidden = true
  24. }
  25. }
  26. }
  27. override init(frame frameRect: NSRect) {
  28. super.init(frame: frameRect)
  29. addSubview(backGroundView)
  30. addSubview(label)
  31. addSubview(selectedLabel)
  32. self.addSubview(self.button)
  33. selectedLabel.stringValue = ""
  34. }
  35. required init?(coder: NSCoder) {
  36. fatalError("init(coder:) has not been implemented")
  37. }
  38. override func layout() {
  39. super.layout()
  40. let width: CGFloat = NSWidth(self.bounds)
  41. let heigth : CGFloat = NSHeight(self.bounds)
  42. backGroundView.frame = NSMakeRect(10, 10, width-20, heigth-20)
  43. let labelH: CGFloat = 20
  44. label.frame = NSMakeRect(35, (heigth-labelH)*0.5, width-35-50, labelH)
  45. selectedLabel.frame = NSMakeRect(width-50, (heigth-labelH)*0.5, 50, labelH)
  46. let buttonH: CGFloat = 22
  47. let buttonY: CGFloat = (heigth-buttonH) * 0.5
  48. self.button.frame = NSMakeRect(10, buttonY, width-17, buttonH)
  49. }
  50. }