added a placeholder
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
1c01fabef0
commit
d7086b0702
@ -41,10 +41,23 @@ open class TextView: UITextView, ViewProtocol, Errorable {
|
|||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
open var placeholder: String? {
|
||||||
|
didSet {
|
||||||
|
placeholderLabel.text = placeholder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open var placeholderLabel = Label().with {
|
||||||
|
$0.textColorConfiguration = ViewColorConfiguration().with {
|
||||||
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true)
|
||||||
|
$0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: false)
|
||||||
|
}.eraseToAnyColorable()
|
||||||
|
}
|
||||||
|
|
||||||
/// Key of whether or not updateView() is called in setNeedsUpdate()
|
/// Key of whether or not updateView() is called in setNeedsUpdate()
|
||||||
open var shouldUpdateView: Bool = true
|
open var shouldUpdateView: Bool = true
|
||||||
|
|
||||||
@ -88,6 +101,7 @@ open class TextView: UITextView, ViewProtocol, Errorable {
|
|||||||
if textAlignment != oldValue {
|
if textAlignment != oldValue {
|
||||||
// Text alignment can be part of our paragraph style, so we may need to
|
// Text alignment can be part of our paragraph style, so we may need to
|
||||||
// re-style when changed
|
// re-style when changed
|
||||||
|
placeholderLabel.textAlignment = textAlignment
|
||||||
updateLabel()
|
updateLabel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,6 +132,9 @@ open class TextView: UITextView, ViewProtocol, Errorable {
|
|||||||
done.pinCenterY()
|
done.pinCenterY()
|
||||||
.pinTrailing(16)
|
.pinTrailing(16)
|
||||||
inputAccessoryView = accessView
|
inputAccessoryView = accessView
|
||||||
|
|
||||||
|
addSubview(placeholderLabel)
|
||||||
|
placeholderLabel.pinToSuperView()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func doneButtonAction() {
|
@objc func doneButtonAction() {
|
||||||
@ -145,7 +162,11 @@ open class TextView: UITextView, ViewProtocol, Errorable {
|
|||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override func layoutSubviews() {
|
||||||
|
super.layoutSubviews()
|
||||||
|
placeholderLabel.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Accessibility
|
// MARK: - Accessibility
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -297,6 +318,9 @@ open class TextView: UITextView, ViewProtocol, Errorable {
|
|||||||
} else {
|
} else {
|
||||||
attributedText = nil
|
attributedText = nil
|
||||||
}
|
}
|
||||||
|
placeholderLabel.textStyle = textStyle
|
||||||
|
placeholderLabel.isHidden = !text.isEmpty
|
||||||
|
placeholderLabel.surface = surface
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user