added done button
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
fd0c8a27ec
commit
91cb21eb04
@ -10,6 +10,25 @@ import UIKit
|
|||||||
|
|
||||||
@objc(VDSTextField)
|
@objc(VDSTextField)
|
||||||
open class TextField: UITextField {
|
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
|
var horizontalPadding: CGFloat = 0
|
||||||
|
|
||||||
open override func textRect(forBounds bounds: CGRect) -> CGRect {
|
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 {
|
open override func becomeFirstResponder() -> Bool {
|
||||||
let success = super.becomeFirstResponder()
|
let success = super.becomeFirstResponder()
|
||||||
if isSecureTextEntry, let text {
|
if isSecureTextEntry, let text {
|
||||||
|
|||||||
@ -97,7 +97,6 @@ open class TextView: UITextView, ViewProtocol {
|
|||||||
initialSetupPerformed = true
|
initialSetupPerformed = true
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
accessibilityCustomActions = []
|
|
||||||
setup()
|
setup()
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
@ -106,8 +105,25 @@ open class TextView: UITextView, ViewProtocol {
|
|||||||
|
|
||||||
open func setup() {
|
open func setup() {
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
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() {
|
open func updateView() {
|
||||||
updateLabel()
|
updateLabel()
|
||||||
}
|
}
|
||||||
@ -118,7 +134,6 @@ open class TextView: UITextView, ViewProtocol {
|
|||||||
shouldUpdateView = false
|
shouldUpdateView = false
|
||||||
surface = .light
|
surface = .light
|
||||||
text = nil
|
text = nil
|
||||||
accessibilityCustomActions = []
|
|
||||||
shouldUpdateView = true
|
shouldUpdateView = true
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user