added done button

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-05-06 09:24:30 -05:00
parent fd0c8a27ec
commit 91cb21eb04
2 changed files with 55 additions and 2 deletions

View File

@ -10,6 +10,25 @@ import UIKit
@objc(VDSTextField)
open class TextField: UITextField {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
required public init() {
super.init(frame: .zero)
initialSetup()
}
public override init(frame: CGRect) {
super.init(frame: .zero)
initialSetup()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
initialSetup()
}
var horizontalPadding: CGFloat = 0
open override func textRect(forBounds bounds: CGRect) -> CGRect {
@ -35,6 +54,25 @@ open class TextField: UITextField {
}
}
open func initialSetup() {
let doneToolbar: UIToolbar = UIToolbar()
doneToolbar.translatesAutoresizingMaskIntoConstraints = false
doneToolbar.barStyle = .default
let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(self.doneButtonAction))
done.accessibilityHint = "Double tap to finish editing."
doneToolbar.items = [flexSpace, done]
doneToolbar.sizeToFit()
inputAccessoryView = doneToolbar
}
@objc func doneButtonAction() {
// Resigns the first responder status when 'Done' is tapped
resignFirstResponder()
}
open override func becomeFirstResponder() -> Bool {
let success = super.becomeFirstResponder()
if isSecureTextEntry, let text {

View File

@ -97,7 +97,6 @@ open class TextView: UITextView, ViewProtocol {
initialSetupPerformed = true
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = []
setup()
setNeedsUpdate()
}
@ -106,8 +105,25 @@ open class TextView: UITextView, ViewProtocol {
open func setup() {
translatesAutoresizingMaskIntoConstraints = false
let doneToolbar: UIToolbar = UIToolbar()
doneToolbar.translatesAutoresizingMaskIntoConstraints = false
doneToolbar.barStyle = .default
let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(self.doneButtonAction))
done.accessibilityHint = "Double tap to finish editing."
doneToolbar.items = [flexSpace, done]
doneToolbar.sizeToFit()
inputAccessoryView = doneToolbar
}
@objc func doneButtonAction() {
// Resigns the first responder status when 'Done' is tapped
resignFirstResponder()
}
open func updateView() {
updateLabel()
}
@ -118,7 +134,6 @@ open class TextView: UITextView, ViewProtocol {
shouldUpdateView = false
surface = .light
text = nil
accessibilityCustomActions = []
shouldUpdateView = true
setNeedsUpdate()
}