KMUserFbEmailItemView.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // KMUserFbEmailItemView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by tangchao on 2024/7/11.
  6. //
  7. import Cocoa
  8. class KMUserFbEmailItemView: NSView, NibLoadable {
  9. @IBOutlet weak var titleLabel: NSTextField!
  10. @IBOutlet weak var box: NSBox!
  11. @IBOutlet weak var textfiled: KMTextField!
  12. @IBOutlet weak var tipLabel: NSTextField!
  13. override func awakeFromNib() {
  14. super.awakeFromNib()
  15. let title = NSLocalizedString("Email", comment: "")
  16. let attri = NSMutableAttributedString(string: title)
  17. attri.addAttribute(.font, value: NSFont.systemFont(ofSize: 13), range: NSMakeRange(0, title.count))
  18. 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)]))
  19. self.titleLabel.attributedStringValue = attri
  20. self.box.borderWidth = 1
  21. self.box.borderColor = NSColor(white: 0, alpha: 0.2)
  22. self.box.fillColor = .white
  23. self.textfiled.drawsBackground = false
  24. self.textfiled.isBordered = false
  25. // self.textfiled.focusRingType = .none
  26. self.textfiled.placeholderString = NSLocalizedString("Your email", comment: "")
  27. self.textfiled.delegate = self
  28. self.textfiled.wantsLayer = true
  29. self.textfiled.layer?.cornerRadius = 4
  30. self.textfiled.layer?.masksToBounds = true
  31. self.textfiled.firstResponderHandler = { [weak self] result in
  32. if result {
  33. self?.box.borderColor = NSColor.km_init(hex: "#1770F4")
  34. } else {
  35. self?.box.borderColor = NSColor(white: 0, alpha: 0.2)
  36. }
  37. }
  38. self.tipLabel.textColor = NSColor.km_init(hex: "#FA1E5D")
  39. self.tipLabel.font = NSFont(name: "SFProText-Regular", size: 11)
  40. self.tipLabel.isHidden = true
  41. }
  42. func string() -> String {
  43. return self.textfiled.stringValue
  44. }
  45. func showTip(label: String) {
  46. self.window?.makeFirstResponder(self.textfiled)
  47. self.box.horLightShakeAnimation()
  48. self.tipLabel.stringValue = label
  49. self.tipLabel.isHidden = false
  50. }
  51. func hiddenTip() {
  52. self.tipLabel.isHidden = true
  53. }
  54. }
  55. extension KMUserFbEmailItemView: NSTextFieldDelegate {
  56. func control(_ control: NSControl, textShouldBeginEditing fieldEditor: NSText) -> Bool {
  57. return true
  58. }
  59. func controlTextDidBeginEditing(_ obj: Notification) {
  60. }
  61. func controlTextDidEndEditing(_ obj: Notification) {
  62. if self.textfiled.isEqual(to: obj.object) {
  63. self.box.borderColor = NSColor(white: 0, alpha: 0.2)
  64. }
  65. }
  66. func controlTextDidChange(_ obj: Notification) {
  67. if self.textfiled.isEqual(to: obj.object) {
  68. self.hiddenTip()
  69. }
  70. }
  71. }