KMPDFMergeSizeTabelViewCell.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // KMPDFMergeSizeTabelViewCell.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/10/12.
  6. //
  7. import Cocoa
  8. @objcMembers class KMPDFMergeSizeTabelViewCell: NSTableCellView {
  9. var label: NSTextField?
  10. var button: NSButton?
  11. var callback: KMEmptyBlock?
  12. override init(frame frameRect: NSRect) {
  13. super.init(frame: frameRect)
  14. self.initSubviews()
  15. }
  16. required init?(coder: NSCoder) {
  17. super.init(coder: coder)
  18. self.initSubviews()
  19. }
  20. override var isFlipped: Bool {
  21. return true
  22. }
  23. func initSubviews() {
  24. var label = NSTextField(labelWithString: "")
  25. label.textColor = NSColor(red: 148.0/255.0, green: 152.0/255.0, blue: 156.0/255.0, alpha: 1.0)
  26. label.font = .SFProTextRegularFont(14)
  27. self.addSubview(label)
  28. self.label = label
  29. var button = NSButton()
  30. button.isBordered = false
  31. button.image = NSImage(named: "KMImageNameSecureClearIcon")
  32. self.addSubview(button)
  33. self.button = button
  34. self.button?.target = self
  35. self.button?.action = #selector(buttonAction)
  36. }
  37. override func layout() {
  38. super.layout()
  39. let height = NSHeight(self.bounds)
  40. let labelH = 22.0
  41. self.label?.frame = NSMakeRect(16, (height-labelH)*0.5, 70, labelH)
  42. let buttonSize = 20.0
  43. self.button?.frame = NSMakeRect(NSMaxX(self.label?.frame ?? NSZeroRect)+5, (height-buttonSize)*0.5, buttonSize, buttonSize)
  44. }
  45. @objc func buttonAction() {
  46. guard let data = self.callback else {
  47. return
  48. }
  49. data()
  50. }
  51. }