// // KMSecureTextField.swift // PDF Reader Pro // // Created by wanjun on 2024/10/25. // import Cocoa class KMSecureTextField: NSTextField { private var actualText: String = "" private var _isVisible: Bool = false var isVisible: Bool { get { return _isVisible } set { _isVisible = newValue if isVisible { super.stringValue = actualText } else { super.stringValue = String(repeating: "*", count: actualText.count) } } } override var stringValue: String { get { return actualText } set { actualText = newValue if isVisible { super.stringValue = actualText } else { super.stringValue = String(repeating: "*", count: actualText.count) } } } // MARK: Notification override func textDidChange(_ notification: Notification) { if let textField = notification.object as? NSTextField { actualText = textField.stringValue if isVisible { super.stringValue = actualText } else { super.stringValue = String(repeating: "*", count: actualText.count) } } if let textView = notification.object as? NSTextView { actualText = textView.string // if isVisible { // super.stringValue = actualText // } else { // super.stringValue = String(repeating: "*", count: actualText.count) // } } } }