KMCancelSubscribeSuccessCellView.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // KMCancelSubscribeSuccessCellView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/12/22.
  6. //
  7. import Cocoa
  8. class KMCancelSubscribeSuccessOtherCellView: KMCancelSubscribeSuccessCellView {
  9. private lazy var inputBox_: NSBox = {
  10. let view = NSBox()
  11. view.boxType = .custom
  12. view.titlePosition = .noTitle
  13. view.contentViewMargins = .zero
  14. view.borderWidth = 2
  15. return view
  16. }()
  17. private lazy var scrollView_: NSScrollView = {
  18. let view = NSScrollView()
  19. return view
  20. }()
  21. private lazy var textView_: NSTextView = {
  22. let view = NSTextView()
  23. view.km_placeholderString = NSLocalizedString("What is your problem?", comment: "")
  24. return view
  25. }()
  26. var inputBox: NSBox {
  27. get {
  28. return inputBox_
  29. }
  30. }
  31. var textView: NSTextView {
  32. get {
  33. return textView_
  34. }
  35. }
  36. var valueDidChange: KMValueDidChangeBlock?
  37. override func initSubViews() {
  38. super.initSubViews()
  39. addSubview(inputBox_)
  40. inputBox_.contentView?.addSubview(scrollView_)
  41. scrollView_.documentView = textView_
  42. scrollView_.drawsBackground = false
  43. textView_.backgroundColor = .clear
  44. textView.delegate = self
  45. contentBox.mas_remakeConstraints { make in
  46. make?.leading.mas_equalTo()(0)
  47. make?.trailing.mas_equalTo()(0)
  48. make?.top.mas_equalTo()(7)
  49. }
  50. inputBox_.mas_makeConstraints { make in
  51. make?.leading.mas_equalTo()(0)
  52. make?.trailing.mas_equalTo()(0)
  53. make?.top.equalTo()(self.contentBox.mas_bottom)?.offset()(12)
  54. make?.height.mas_equalTo()(80)
  55. make?.bottom.mas_equalTo()(-7)
  56. }
  57. scrollView_.mas_makeConstraints { make in
  58. make?.leading.mas_equalTo()(16)
  59. make?.trailing.mas_equalTo()(-16)
  60. make?.top.mas_equalTo()(16)
  61. make?.bottom.mas_equalTo()(0)
  62. }
  63. // textView_.mas_makeConstraints { make in
  64. // make?.leading.mas_equalTo()(0)
  65. // make?.trailing.mas_equalTo()(0)
  66. // make?.top.mas_equalTo()(0)
  67. // make?.height.mas_equalTo()(64)
  68. // }
  69. }
  70. override func layout() {
  71. super.layout()
  72. textView_.frame = scrollView_.contentView.bounds
  73. }
  74. }
  75. extension KMCancelSubscribeSuccessOtherCellView: NSTextViewDelegate {
  76. func textDidChange(_ notification: Notification) {
  77. if textView.isEqual(to: notification.object) {
  78. textView.placeholderLabel.isHidden = (textView.string.isEmpty == false)
  79. valueDidChange?(textView.string, nil)
  80. }
  81. }
  82. func textDidEndEditing(_ notification: Notification) {
  83. if textView.isEqual(to: notification.object) {
  84. textView.placeholderLabel.isHidden = (textView.string.isEmpty == false)
  85. }
  86. }
  87. }
  88. class KMCancelSubscribeSuccessCellView: NSTableCellView {
  89. private lazy var contentBox_: NSBox = {
  90. let view = NSBox()
  91. view.boxType = .custom
  92. view.titlePosition = .noTitle
  93. view.contentViewMargins = .zero
  94. view.borderWidth = 2
  95. return view
  96. }()
  97. private lazy var radio_: NSButton = {
  98. let view = NSButton(radioButtonWithTitle: "", target: self, action: #selector(radioAction))
  99. return view
  100. }()
  101. var contentBox: NSBox {
  102. get {
  103. return contentBox_
  104. }
  105. }
  106. var radio: NSButton {
  107. get {
  108. return radio_
  109. }
  110. }
  111. var itemClick: KMEmptyBlock?
  112. convenience init() {
  113. self.init(frame: .init(x: 0, y: 0, width: 200, height: 30))
  114. initSubViews()
  115. }
  116. override func awakeFromNib() {
  117. super.awakeFromNib()
  118. initSubViews()
  119. }
  120. func initSubViews() {
  121. addSubview(contentBox_)
  122. contentBox_.contentView?.addSubview(radio_)
  123. contentBox_.mas_makeConstraints { make in
  124. make?.leading.mas_equalTo()(0)
  125. make?.trailing.mas_equalTo()(0)
  126. make?.top.mas_equalTo()(7)
  127. make?.bottom.mas_equalTo()(-7)
  128. }
  129. radio_.mas_makeConstraints { make in
  130. make?.leading.mas_equalTo()(16)
  131. make?.trailing.mas_equalTo()(-16)
  132. make?.top.mas_equalTo()(11)
  133. make?.bottom.mas_equalTo()(-11)
  134. }
  135. }
  136. @objc func radioAction() {
  137. itemClick?()
  138. }
  139. }