added a format label
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
ba0989bb2b
commit
8a686314f5
@ -47,6 +47,17 @@ open class TextField: UITextField, ViewProtocol, Errorable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
private var formatLabel = Label().with {
|
||||
$0.tag = 999
|
||||
$0.textColorConfiguration = ViewColorConfiguration().with {
|
||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true)
|
||||
$0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: false)
|
||||
}.eraseToAnyColorable()
|
||||
}
|
||||
|
||||
/// Format String similar to placeholder
|
||||
open var formatText: String?
|
||||
|
||||
/// TextStyle used on the titleLabel.
|
||||
open var textStyle: TextStyle = .defaultStyle { didSet { setNeedsUpdate() } }
|
||||
|
||||
@ -114,6 +125,37 @@ open class TextField: UITextField, ViewProtocol, Errorable {
|
||||
|
||||
open func updateView() {
|
||||
updateLabel()
|
||||
updateFormat()
|
||||
}
|
||||
|
||||
open func updateFormat() {
|
||||
guard let formatText else {
|
||||
formatLabel.text = ""
|
||||
return
|
||||
}
|
||||
|
||||
if viewWithTag(999) == nil {
|
||||
addSubview(formatLabel)
|
||||
formatLabel.pinToSuperView()
|
||||
}
|
||||
|
||||
var attributes: [any LabelAttributeModel]?
|
||||
var finalFormatText = formatText
|
||||
|
||||
if let text, !text.isEmpty {
|
||||
//make the color of the matching text clear
|
||||
attributes = [ColorLabelAttribute(location: 0, length: text.count, color: .clear)]
|
||||
|
||||
let startIndex = formatText.index(formatText.startIndex, offsetBy: text.count)
|
||||
if startIndex < formatText.endIndex {
|
||||
finalFormatText = text + formatText[startIndex...]
|
||||
}
|
||||
}
|
||||
|
||||
//set the label
|
||||
formatLabel.surface = surface
|
||||
formatLabel.text = finalFormatText
|
||||
formatLabel.attributes = attributes
|
||||
}
|
||||
|
||||
open func updateAccessibility() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user