KMSignUpBuyView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // KMSignUpBuyView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/12/11.
  6. //
  7. import Cocoa
  8. class KMSignUpBuyView: KMHoverView {
  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: NSLocalizedString("Buy without Logging in", tableName: "MemberCenterLocalizable", comment: ""))
  19. view.font = .SFProTextBoldFont(12)
  20. return view
  21. }()
  22. private lazy var subTitleLabel_: NSTextField = {
  23. let view = NSTextField(wrappingLabelWithString: NSLocalizedString("Cross-platform not supported, 1-year free AI not available", tableName: "MemberCenterLocalizable", comment: ""))
  24. view.font = .SFProTextRegularFont(11)
  25. return view
  26. }()
  27. private lazy var arrowButton_: NSButton = {
  28. let view = NSButton()
  29. view.isBordered = false
  30. view.imagePosition = .imageOnly
  31. view.image = NSImage(named: "BuyNewArrowImage2Hover")
  32. return view
  33. }()
  34. private lazy var actionButton_: NSButton = {
  35. let view = NSButton()
  36. view.isBordered = false
  37. view.title = ""
  38. view.target = self
  39. view.action = #selector(buttonAction)
  40. return view
  41. }()
  42. private lazy var leftLine_: NSView = {
  43. let view = NSView()
  44. view.wantsLayer = true
  45. return view
  46. }()
  47. var contentBox: NSBox {
  48. get {
  49. return contentBox_
  50. }
  51. }
  52. var titleLabel: NSTextField {
  53. get {
  54. return titleLabel_
  55. }
  56. }
  57. var subTitleLabel: NSTextField {
  58. get {
  59. return subTitleLabel_
  60. }
  61. }
  62. var leftLine: NSView {
  63. get {
  64. return leftLine_
  65. }
  66. }
  67. var itemClick: KMCommonClickBlock?
  68. convenience init() {
  69. self.init(frame: .init(x: 0, y: 0, width: 200, height: 40))
  70. initSubViews()
  71. }
  72. override func awakeFromNib() {
  73. super.awakeFromNib()
  74. initSubViews()
  75. }
  76. func initSubViews() {
  77. let contentInset = NSEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
  78. addSubview(contentBox_)
  79. contentBox_.km_add_inset_constraint()
  80. let wh: CGFloat = 16
  81. contentBox_.contentView?.addSubview(arrowButton_)
  82. arrowButton_.km_add_size_constraint(size: .init(width: wh, height: wh))
  83. arrowButton_.km_add_trailing_constraint(constant: -contentInset.right)
  84. arrowButton_.km_add_centerY_constraint()
  85. let hSpace: CGFloat = 4
  86. contentBox_.contentView?.addSubview(titleLabel_)
  87. titleLabel_.km_add_leading_constraint(constant: contentInset.left)
  88. titleLabel_.km_add_top_constraint(constant: 4)
  89. titleLabel_.km_add_trailing_constraint(equalTo: arrowButton_, attribute: .leading, constant: hSpace)
  90. contentBox_.contentView?.addSubview(subTitleLabel_)
  91. subTitleLabel_.km_add_leading_constraint(constant: contentInset.left)
  92. // subTitleLabel_.km_add_top_constraint(equalTo: titleLabel_, attribute: .bottom, constant: 4)
  93. subTitleLabel.km_add_centerY_constraint(constant: 8)
  94. subTitleLabel_.km_add_trailing_constraint(equalTo: arrowButton_, attribute: .leading, constant: hSpace)
  95. contentBox.contentView?.addSubview(leftLine_)
  96. leftLine_.km_add_leading_constraint(constant: 0)
  97. leftLine_.km_add_top_constraint(constant: 0)
  98. leftLine_.km_add_width_constraint(constant: 2)
  99. leftLine_.km_add_bottom_constraint(constant: 0)
  100. contentBox.contentView?.addSubview(actionButton_)
  101. actionButton_.km_add_inset_constraint()
  102. }
  103. @objc func buttonAction() {
  104. itemClick?(1)
  105. }
  106. }