KMConvertSettingLimitTipView.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // KMConvertSettingLimitTipView.swift
  3. // PDF Reader Pro
  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. var contentView: NSView {
  14. get {
  15. return self._contentView
  16. }
  17. }
  18. var itemClick: KMCommonClickBlock?
  19. override init(frame frameRect: NSRect) {
  20. super.init(frame: frameRect)
  21. self.initSubViews()
  22. self.initDefaultValue()
  23. }
  24. required init?(coder: NSCoder) {
  25. super.init(coder: coder)
  26. self.initSubViews()
  27. self.initDefaultValue()
  28. }
  29. func initSubViews() {
  30. self.addSubview(self.contentView)
  31. self.contentView.addSubview(self._iconIv)
  32. self.contentView.addSubview(self._textField)
  33. self.contentView.addSubview(self._funcBox)
  34. self.contentView.km_add_inset_constraint()
  35. self._iconIv.km_add_leading_constraint(constant: 10)
  36. self._iconIv.km_add_centerY_constraint()
  37. self._textField.km_add_leading_constraint(equalTo: self._iconIv, attribute: .trailing, constant: 5)
  38. self._textField.km_add_centerY_constraint(equalTo: self._iconIv)
  39. self._funcBox.km_add_leading_constraint(equalTo: self._textField, attribute: .trailing)
  40. self._funcBox.km_add_centerY_constraint(equalTo: self._iconIv)
  41. self._funcBox.km_add_size_constraint(size: NSMakeSize(60, 30))
  42. }
  43. func initDefaultValue() {
  44. self._iconIv.image = NSImage(named: "KMImageNameTipNormal")
  45. self._textField.stringValue = NSLocalizedString("Convert the first 10 pages for free", comment: "")
  46. self._textField.font = .SFProTextRegularFont(12)
  47. self._textField.textColor = KMAppearance.titleColor()
  48. self._textField.textColor = NSColor.km_init(hex: "#F3465B")
  49. self._funcBox.boxType = .custom
  50. self._funcBox.titlePosition = .noTitle
  51. self._funcBox.borderWidth = 0.0
  52. }
  53. @objc private func funcAction() {
  54. guard let callback = self.itemClick else {
  55. return
  56. }
  57. callback(1)
  58. }
  59. }