vds_ios/VDS/Components/TextFields/InputField/TextField.swift
Matt Bruce 5627c1b76e refactored out TextField
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-05-01 14:32:46 -05:00

47 lines
1.2 KiB
Swift

//
// 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
}
}