KMPageEditBaseItemView.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // KMPageEditBaseItemView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/1/11.
  6. //
  7. import Cocoa
  8. typealias KMPageEditItemViewItemClick = (_ index: Int, _ value: Any) -> ()
  9. class KMPageEditBaseItemView: NSView {
  10. lazy var titleLabel: NSTextField = {
  11. let label = NSTextField(labelWithString: "")
  12. label.font = NSFont.systemFont(ofSize: 14)
  13. return label
  14. }()
  15. private var myContentInset: NSEdgeInsets = NSEdgeInsetsMake(8, 16, 0, 0)
  16. var contentInset: NSEdgeInsets {
  17. get {
  18. return myContentInset
  19. }
  20. set {
  21. self.myContentInset = newValue
  22. self.layoutSubtreeIfNeeded()
  23. }
  24. }
  25. var itemClick: KMPageEditItemViewItemClick!
  26. override var isFlipped: Bool {
  27. return true
  28. }
  29. override init(frame frameRect: NSRect) {
  30. super.init(frame: frameRect)
  31. initSubviews()
  32. }
  33. required init?(coder: NSCoder) {
  34. super.init(coder: coder)
  35. initSubviews()
  36. }
  37. public func initSubviews() {
  38. self.addSubview(self.titleLabel)
  39. }
  40. override func layout() {
  41. super.layout()
  42. self.titleLabel.frame = NSMakeRect(self.contentInset.left, self.contentInset.top, NSWidth(self.bounds)-self.contentInset.left-self.contentInset.right, 22)
  43. }
  44. }