KMProductCompareDiscountView.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // KMProductCompareDiscountView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2025/1/11.
  6. //
  7. import Cocoa
  8. @objcMembers class KMProductCompareDiscountView: NSView {
  9. private lazy var backgroundIv_: NSImageView = {
  10. let view = NSImageView()
  11. return view
  12. }()
  13. private lazy var label_: NSTextField = {
  14. let view = NSTextField(labelWithString: "")
  15. view.font = .UbuntuMediumFontWithSize(13)
  16. view.textColor = .white
  17. return view
  18. }()
  19. var backgroundIv: NSImageView {
  20. get {
  21. return backgroundIv_
  22. }
  23. }
  24. var label: NSTextField {
  25. get {
  26. return label_
  27. }
  28. }
  29. convenience init() {
  30. self.init(frame: .init(x: 0, y: 0, width: 80, height: 40))
  31. initSubviews()
  32. }
  33. override func awakeFromNib() {
  34. super.awakeFromNib()
  35. initSubviews()
  36. }
  37. func initSubviews() {
  38. addSubview(backgroundIv_)
  39. addSubview(label_)
  40. backgroundIv_.mas_makeConstraints { make in
  41. make?.center.mas_equalTo()(0)
  42. make?.width.equalTo()(self)
  43. }
  44. label_.mas_makeConstraints { make in
  45. make?.centerX.mas_equalTo()(0)
  46. make?.centerY.mas_equalTo()(-2)
  47. }
  48. }
  49. override func layout() {
  50. super.layout()
  51. backgroundIv.image?.size = self.frame.size
  52. }
  53. }