KMPresentTableViewCell.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // KMPresentTableViewCell.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 5/14/24.
  6. //
  7. import Cocoa
  8. @objc enum KMPresentTableViewCellType: Int {
  9. case img = 0
  10. case text
  11. }
  12. class KMPresentTableViewCell: NSTableCellView{
  13. var contentView: NSView?
  14. var iv: NSImageView?
  15. var label: NSTextField?
  16. var type: KMPresentTableViewCellType?
  17. convenience init(type: KMPresentTableViewCellType) {
  18. self.init()
  19. // switch type {
  20. // case .img:
  21. // configuUIForImg()
  22. // case .text:
  23. // configuUIForText()
  24. // default:
  25. // break
  26. // }
  27. configuUi()
  28. self.type = type
  29. }
  30. // convenience init() {
  31. // self.init()
  32. // configuUi()
  33. // }
  34. func configuUIForImg() {
  35. self.iv = NSImageView(frame: .zero)
  36. self.addSubview(self.iv!)
  37. self.iv?.mas_makeConstraints({ make in
  38. make?.edges.equalTo()(self)
  39. // make?.left.equalTo()(self)
  40. // make?.top.equalTo()(self)?.offset()(12)
  41. // make?.width.equalTo()(16)
  42. // make?.height.equalTo()(16)
  43. })
  44. }
  45. func configuUIForText() {
  46. let tf = NSTextField(frame: .zero)
  47. self.label = tf
  48. self.label?.isBordered = false
  49. self.label?.drawsBackground = true
  50. self.label?.backgroundColor = NSColor.clear
  51. self.label?.isEditable = false
  52. self.addSubview(self.label!)
  53. self.label?.mas_makeConstraints({ make in
  54. make?.top.equalTo()(self)?.offset()(13)
  55. make?.left.equalTo()(self)
  56. })
  57. self.label?.textColor = KMAppearance.Layout.h0Color()
  58. self.label?.font = NSFont.systemFont(ofSize: 12)
  59. }
  60. func configuUi() {
  61. self.iv = NSImageView(frame: .zero)
  62. self.addSubview(self.iv!)
  63. self.iv?.mas_makeConstraints({ make in
  64. make?.left.equalTo()(0)
  65. make?.top.equalTo()(0)
  66. make?.width.equalTo()(32)
  67. make?.bottom.equalTo()(0)
  68. })
  69. let tf = NSTextField(frame: .zero)
  70. self.label = tf
  71. self.label?.isBordered = false
  72. self.label?.drawsBackground = true
  73. self.label?.backgroundColor = NSColor.clear
  74. self.label?.isEditable = false
  75. self.addSubview(self.label!)
  76. self.label?.mas_makeConstraints({ make in
  77. // make?.top.equalTo()(self)?.offset()(13)
  78. make?.left.equalTo()(self.iv?.mas_right)
  79. make?.right.equalTo()(self)
  80. make?.centerY.equalTo()(self)
  81. })
  82. self.label?.textColor = KMAppearance.Layout.h0Color()
  83. self.label?.font = NSFont.systemFont(ofSize: 12)
  84. self.label?.maximumNumberOfLines = 1
  85. }
  86. }