KMFunctionGuideNameItemView.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // KMFunctionGuideNameItemView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/8.
  6. //
  7. import Cocoa
  8. class KMFunctionGuideNameItemView: NSView, NibLoadable {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var iconImg: NSImageView!
  11. @IBOutlet weak var nameLabel: NSTextField!
  12. var _infoDict = NSDictionary()
  13. var _isSelected = false
  14. var clickHandle: ((_ view: KMFunctionGuideNameItemView)->Void)?
  15. override func draw(_ dirtyRect: NSRect) {
  16. super.draw(dirtyRect)
  17. // Drawing code here.
  18. }
  19. override func awakeFromNib() {
  20. super.awakeFromNib()
  21. self.setUp()
  22. }
  23. func setUp() {
  24. self.contendView.wantsLayer = true
  25. self.contendView.layer?.cornerRadius = 4
  26. self.contendView.layer?.masksToBounds = true
  27. self.nameLabel.font = NSFont.SFProTextSemiboldFont(14)
  28. self.updateViewColor()
  29. }
  30. func updateViewColor() {
  31. if KMAppearance.isDarkMode() {
  32. self.nameLabel.textColor = NSColor(red: 200/255, green: 201/255, blue: 204/255, alpha: 1)
  33. self.contendView.layer?.backgroundColor = NSColor.clear.cgColor
  34. self.iconImg.image = NSImage(named: "whatNewItemNormal")
  35. } else {
  36. self.nameLabel.textColor = NSColor(red: 66/255, green: 70/255, blue: 77/255, alpha: 1)
  37. self.contendView.layer?.backgroundColor = NSColor.clear.cgColor
  38. self.iconImg.image = NSImage(named: "whatNewItemNormal")
  39. }
  40. }
  41. //MARK: Setter
  42. var infoDict: NSDictionary {
  43. set {
  44. _infoDict = newValue
  45. self.nameLabel.stringValue = NSLocalizedString(self.infoDict["name"] as! String, comment: "")
  46. }
  47. get {
  48. return _infoDict
  49. }
  50. }
  51. var isSelected: Bool {
  52. set {
  53. _isSelected = newValue
  54. self.updateViewColor()
  55. }
  56. get {
  57. return _isSelected
  58. }
  59. }
  60. //MARK: IBAction
  61. @IBAction func clickAction(_ sender: Any) {
  62. guard let callBack = self.clickHandle else {
  63. return
  64. }
  65. callBack(self)
  66. }
  67. }