KMUserFbDespItemView.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // KMUserFbDespItemView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by tangchao on 2024/7/11.
  6. //
  7. import Cocoa
  8. class KMUserFbDespItemView: NSView, NibLoadable {
  9. @IBOutlet weak var titleLabel: NSTextField!
  10. @IBOutlet weak var box: NSBox!
  11. @IBOutlet weak var scrollView: NSScrollView!
  12. @IBOutlet var textView: NSTextView!
  13. @IBOutlet weak var tipLabel: NSTextField!
  14. override func awakeFromNib() {
  15. super.awakeFromNib()
  16. let title = NSLocalizedString("Describe Question", comment: "")
  17. let attri = NSMutableAttributedString(string: title)
  18. attri.addAttribute(.font, value: NSFont.systemFont(ofSize: 13), range: NSMakeRange(0, title.count))
  19. attri.append(.init(string: "*", attributes: [NSAttributedString.Key.font : NSFont.systemFont(ofSize: 13), NSAttributedString.Key.foregroundColor : NSColor(red: 250/255.0, green: 31/255.0, blue: 93/255.0, alpha: 1.0)]))
  20. self.titleLabel.attributedStringValue = attri
  21. self.textView.textContainerInset = NSSize(width: 6, height: 6)
  22. self.textView.km_placeholderString = NSLocalizedString("Please tell us the details so that we can help you faster", comment: "")
  23. self.textView.delegate = self
  24. self.box.borderWidth = 0.5
  25. self.box.cornerRadius = 5
  26. self.box.borderColor = NSColor(white: 0, alpha: 0.08)
  27. // self.textView.font = [NSFont systemFontOfSize:12];
  28. // self.textView.textColor = [NSColor colorWithRed:81/255.f green:91/255.f blue:117/255.f alpha:1.f];
  29. self.textView.enclosingScrollView?.wantsLayer = true
  30. self.textView.enclosingScrollView?.borderType = .noBorder
  31. self.textView.enclosingScrollView?.layer?.cornerRadius = 5
  32. self.textView.enclosingScrollView?.layer?.masksToBounds = true
  33. self.textView.isRichText = false
  34. self.textView.backgroundColor = .clear
  35. self.tipLabel.stringValue = NSLocalizedString("Please fill in details", comment: "")
  36. self.tipLabel.textColor = NSColor.km_init(hex: "#FA1E5D")
  37. self.tipLabel.font = NSFont(name: "SFProText-Regular", size: 11)
  38. self.tipLabel.isHidden = true
  39. }
  40. func string() -> String {
  41. return self.textView.string
  42. }
  43. func showTip() {
  44. self.window?.makeFirstResponder(self.textView)
  45. self.box.horLightShakeAnimation()
  46. self.tipLabel.isHidden = false
  47. }
  48. func hiddenTip() {
  49. self.tipLabel.isHidden = true
  50. }
  51. }
  52. extension KMUserFbDespItemView: NSTextViewDelegate {
  53. func textViewDidChangeSelection(_ notification: Notification) {
  54. if self.textView.isEqual(to: notification.object) {
  55. self.hiddenTip()
  56. self.textView.placeholderLabel.isHidden = self.textView.string.count > 0
  57. }
  58. }
  59. // func textViewDidChangeTypingAttributes(_ notification: Notification) {
  60. //
  61. // }
  62. func textDidChange(_ notification: Notification) {
  63. if self.textView.isEqual(to: notification.object) {
  64. self.hiddenTip()
  65. self.textView.placeholderLabel.isHidden = self.textView.string.count > 0
  66. }
  67. }
  68. }