// // TextField.swift // VDS // // Created by Matt Bruce on 5/1/24. // import Foundation import UIKit @objc(VDSTextField) open class TextField: UITextField { var horizontalPadding: CGFloat = 0 open override func textRect(forBounds bounds: CGRect) -> CGRect { let rect = super.textRect(forBounds: bounds) return rect.insetBy(dx: -horizontalPadding, dy: 0) } open override func editingRect(forBounds bounds: CGRect) -> CGRect { let rect = super.editingRect(forBounds: bounds) return rect.insetBy(dx: -horizontalPadding, dy: 0) } open override func placeholderRect(forBounds bounds: CGRect) -> CGRect { let rect = super.placeholderRect(forBounds: bounds) return rect.insetBy(dx: -horizontalPadding, dy: 0) } open override var isSecureTextEntry: Bool { didSet { if isFirstResponder { _ = becomeFirstResponder() } } } open override func becomeFirstResponder() -> Bool { let success = super.becomeFirstResponder() if isSecureTextEntry, let text { self.text?.removeAll() insertText(text) } return success } }