KMNTableHeaderCellView.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // KMNTableHeaderCellView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/11/7.
  6. //
  7. import Cocoa
  8. class KMNTableHeaderCellView: NSTableCellView {
  9. private var contentBox: NSBox = {
  10. let box = NSBox()
  11. box.boxType = .custom
  12. box.titlePosition = .noTitle
  13. box.contentViewMargins = .zero
  14. box.borderWidth = 0
  15. return box
  16. }()
  17. private var titleLabel_: NSTextField = {
  18. let view = NSTextField(labelWithString: "")
  19. return view
  20. }()
  21. private var leftVLine_: NSView = {
  22. let view = NSView()
  23. return view
  24. }()
  25. private var rightVLine_: NSView = {
  26. let view = NSView()
  27. return view
  28. }()
  29. private var bottomLine_: NSView = {
  30. let view = NSView()
  31. return view
  32. }()
  33. var titleLabel: NSTextField {
  34. get {
  35. return self.titleLabel_
  36. }
  37. }
  38. var leftLine: NSView {
  39. get {
  40. return self.leftVLine_
  41. }
  42. }
  43. var rightLine: NSView {
  44. get {
  45. return self.rightVLine_
  46. }
  47. }
  48. var bottomLine: NSView {
  49. get {
  50. return self.bottomLine_
  51. }
  52. }
  53. override func draw(_ dirtyRect: NSRect) {
  54. super.draw(dirtyRect)
  55. // Drawing code here.
  56. }
  57. convenience init() {
  58. self.init(frame: .init(x: 0, y: 0, width: 40, height: 40))
  59. initSubviews()
  60. }
  61. override func awakeFromNib() {
  62. super.awakeFromNib()
  63. initSubviews()
  64. }
  65. func initSubviews() {
  66. addSubview(contentBox)
  67. contentBox.km_add_inset_constraint()
  68. contentBox.contentView?.addSubview(leftVLine_)
  69. contentBox.contentView?.addSubview(titleLabel_)
  70. contentBox.contentView?.addSubview(rightVLine_)
  71. contentBox.contentView?.addSubview(bottomLine_)
  72. leftVLine_.km_add_leading_constraint()
  73. leftVLine_.km_add_top_constraint(constant: 4)
  74. leftVLine_.km_add_bottom_constraint(constant: -4)
  75. leftVLine_.km_add_width_constraint(constant: 0.5)
  76. titleLabel_.km_add_leading_constraint(constant: 8)
  77. titleLabel_.km_add_centerY_constraint()
  78. rightVLine_.km_add_trailing_constraint()
  79. rightVLine_.km_add_top_constraint(constant: 4)
  80. rightVLine_.km_add_bottom_constraint(constant: -4)
  81. rightVLine_.km_add_width_constraint(constant: 0.5)
  82. bottomLine_.km_add_bottom_constraint(constant: 0)
  83. bottomLine_.km_add_leading_constraint(constant: 0)
  84. bottomLine_.km_add_trailing_constraint(constant: 0)
  85. bottomLine_.km_add_height_constraint(constant: 1)
  86. contentBox.fillColor = .clear
  87. }
  88. }