KMConvertSettingLimitTipView.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // KMConvertSettingLimitTipView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/6/26.
  6. //
  7. import Cocoa
  8. class KMConvertSettingLimitTipView: NSView {
  9. private var _contentView = NSView()
  10. private var _iconIv = NSImageView()
  11. private var _textField = NSTextField(labelWithString: "")
  12. private var _funcBox = NSBox()
  13. private var _funcButtonVC: KMDesignButton?
  14. var contentView: NSView {
  15. get {
  16. return self._contentView
  17. }
  18. }
  19. var itemClick: KMCommonClickBlock?
  20. override init(frame frameRect: NSRect) {
  21. super.init(frame: frameRect)
  22. self.initSubViews()
  23. self.initDefaultValue()
  24. }
  25. required init?(coder: NSCoder) {
  26. super.init(coder: coder)
  27. self.initSubViews()
  28. self.initDefaultValue()
  29. }
  30. func initSubViews() {
  31. self.addSubview(self.contentView)
  32. self.contentView.addSubview(self._iconIv)
  33. self.contentView.addSubview(self._textField)
  34. self.contentView.addSubview(self._funcBox)
  35. self._funcButtonVC = KMDesignButton(withType: .Text)
  36. self._funcBox.contentView = self._funcButtonVC!.view
  37. self._funcButtonVC?.stringValue = NSLocalizedString("Unlock", comment: "")
  38. self._funcButtonVC?.button(type: .Text, size: .m)
  39. self._funcButtonVC?.target = self
  40. self._funcButtonVC?.action = #selector(funcAction)
  41. self.contentView.km_add_inset_constraint()
  42. self._iconIv.km_add_leading_constraint(constant: 10)
  43. self._iconIv.km_add_centerY_constraint()
  44. self._textField.km_add_leading_constraint(equalTo: self._iconIv, attribute: .trailing, constant: 5)
  45. self._textField.km_add_centerY_constraint(equalTo: self._iconIv)
  46. self._funcBox.km_add_leading_constraint(equalTo: self._textField, attribute: .trailing)
  47. self._funcBox.km_add_centerY_constraint(equalTo: self._iconIv)
  48. self._funcBox.km_add_size_constraint(size: NSMakeSize(60, 30))
  49. }
  50. func initDefaultValue() {
  51. self._iconIv.image = NSImage(named: "KMImageNameTipNormal")
  52. self._textField.stringValue = NSLocalizedString("Convert the first 10 pages for free", comment: "")
  53. self._textField.font = .SFProTextRegular(12)
  54. self._textField.textColor = KMAppearance.titleColor()
  55. self._funcBox.boxType = .custom
  56. self._funcBox.titlePosition = .noTitle
  57. self._funcBox.borderWidth = 0.0
  58. }
  59. @objc private func funcAction() {
  60. guard let callback = self.itemClick else {
  61. return
  62. }
  63. callback(1)
  64. }
  65. }