AccountBenefitCellView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // AccountBenefitCellView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/10/30.
  6. //
  7. import Cocoa
  8. class AccountBenefitCellView: NSTableCellView {
  9. private lazy var contentBox_: NSBox = {
  10. let view = NSBox()
  11. view.boxType = .custom
  12. view.titlePosition = .noTitle
  13. view.contentViewMargins = .zero
  14. view.borderWidth = 0
  15. return view
  16. }()
  17. private lazy var titleLabel_: NSTextField = {
  18. let view = NSTextField(labelWithString: "")
  19. view.font = .systemFont(ofSize: 16)
  20. view.textColor = KMAppearance.titleColor()
  21. return view
  22. }()
  23. private lazy var hotIv_: NSImageView = {
  24. let view = NSImageView()
  25. view.image = NSImage(named: "KMImageNameAccountBenefitHot")
  26. return view
  27. }()
  28. private lazy var subTitleLabel_: NSTextField = {
  29. let view = NSTextField(labelWithString: "")
  30. return view
  31. }()
  32. private lazy var buttonBox_: NSBox = {
  33. let view = NSBox()
  34. view.boxType = .custom
  35. view.titlePosition = .noTitle
  36. view.contentViewMargins = .zero
  37. view.borderWidth = 0
  38. return view
  39. }()
  40. private lazy var button_: NSButton = {
  41. let view = NSButton()
  42. view.isBordered = false
  43. return view
  44. }()
  45. var titleLabel: NSTextField {
  46. get {
  47. return self.titleLabel_
  48. }
  49. }
  50. var subTitleLabel: NSTextField {
  51. get {
  52. return self.subTitleLabel_
  53. }
  54. }
  55. var hotIv: NSImageView {
  56. get {
  57. return self.hotIv_
  58. }
  59. }
  60. var itemClick: KMCommonClickBlock?
  61. override func draw(_ dirtyRect: NSRect) {
  62. super.draw(dirtyRect)
  63. // Drawing code here.
  64. }
  65. convenience init() {
  66. self.init(frame: .init(x: 0, y: 0, width: 200, height: 126))
  67. self.initSubviews()
  68. self.initDefaultValue()
  69. }
  70. override func awakeFromNib() {
  71. super.awakeFromNib()
  72. self.initSubviews()
  73. self.initDefaultValue()
  74. }
  75. func initSubviews() {
  76. self.addSubview(self.contentBox_)
  77. self.contentBox_.contentView?.addSubview(self.titleLabel_)
  78. self.contentBox_.contentView?.addSubview(self.hotIv_)
  79. self.contentBox_.contentView?.addSubview(self.subTitleLabel_)
  80. self.contentBox_.contentView?.addSubview(self.buttonBox_)
  81. self.buttonBox_.contentView?.addSubview(self.button_)
  82. self.contentBox_.km_add_inset_constraint(inset: NSEdgeInsetsMake(10, 10, 10, 10))
  83. self.titleLabel_.km_add_leading_constraint(constant: 20)
  84. self.titleLabel_.km_add_top_constraint(constant: 23)
  85. self.hotIv_.km_add_size_constraint(size: .init(width: 30, height: 16))
  86. self.hotIv_.km_add_centerY_constraint(equalTo: self.titleLabel_)
  87. self.hotIv_.km_add_leading_constraint(equalTo: self.titleLabel_, attribute: .trailing, constant: 2)
  88. self.subTitleLabel_.km_add_leading_constraint(constant: 20)
  89. self.subTitleLabel_.km_add_top_constraint(equalTo: self.titleLabel_, attribute: .bottom, constant: 5)
  90. self.buttonBox_.km_add_right_constraint(constant: -20)
  91. self.buttonBox_.km_add_bottom_constraint(constant: -24)
  92. self.buttonBox_.km_add_height_constraint(constant: 32)
  93. self.button_.km_add_leading_constraint(constant: 24)
  94. self.button_.km_add_right_constraint(constant: -20)
  95. self.button_.km_add_centerY_constraint()
  96. }
  97. func initDefaultValue() {
  98. self.contentBox_.cornerRadius = 8
  99. self.contentBox_.fillColor = NSColor(hex: "#F9F9FD")
  100. self.buttonBox_.cornerRadius = 4
  101. self.buttonBox_.fillColor = KMAppearance.themeColor()
  102. self.button_.title = NSLocalizedString("Buy Now", comment: "")
  103. self.button_.setTitleColor(.white)
  104. self.button_.target = self
  105. self.button_.action = #selector(buttonAction)
  106. }
  107. @objc func buttonAction() {
  108. self.itemClick?(1)
  109. }
  110. }