Commit 822bdd70 by Daniel Dahan

pr-715: added isPlaceholderUppercasedWhenEditing when TextField is in active…

pr-715: added isPlaceholderUppercasedWhenEditing when TextField is in active state or text is not empty, the placeholder label will be capitalized
parent aaac19c6
......@@ -366,9 +366,9 @@ open class TextField: UITextField {
}
@IBInspectable
open var isPlaceholderUppercasedWhenEditing: Bool = false {
open var isPlaceholderUppercasedWhenEditing = false {
didSet {
placeholder = placeholder?.uppercased()
updatePlaceholderTextToActiveState()
}
}
......@@ -503,6 +503,32 @@ fileprivate extension TextField {
placeholderLabel.textColor = isEditing ? placeholderActiveColor : placeholderNormalColor
}
/// Update the placeholder text to the active state.
func updatePlaceholderTextToActiveState() {
guard isPlaceholderUppercasedWhenEditing else {
return
}
guard isEditing || !isEmpty else {
return
}
placeholderLabel.text = placeholderLabel.text?.uppercased()
}
/// Update the placeholder text to the normal state.
func updatePlaceholderTextToNormalState() {
guard isPlaceholderUppercasedWhenEditing else {
return
}
guard isEmpty else {
return
}
placeholderLabel.text = placeholderLabel.text?.capitalized
}
/// Updates the detailLabel text color.
func updateDetailLabelColor() {
detailLabel.textColor = detailColor
......@@ -648,16 +674,12 @@ extension TextField {
updatePlaceholderLabelColor()
guard isPlaceholderAnimated else {
if isPlaceholderUppercasedWhenEditing {
placeholderLabel.text = placeholderLabel.text?.uppercased()
}
updatePlaceholderTextToActiveState()
return
}
guard isEmpty else {
if isPlaceholderUppercasedWhenEditing {
placeholderLabel.text = placeholderLabel.text?.uppercased()
}
updatePlaceholderTextToActiveState()
return
}
......@@ -667,9 +689,8 @@ extension TextField {
}
s.placeholderLabel.transform = CGAffineTransform(scaleX: s.placeholderActiveScale, y: s.placeholderActiveScale)
if self?.isPlaceholderUppercasedWhenEditing ?? false {
s.placeholderLabel.text = s.placeholderLabel.text?.uppercased()
}
s.updatePlaceholderTextToActiveState()
switch s.textAlignment {
case .left, .natural:
......@@ -691,12 +712,12 @@ extension TextField {
}
updatePlaceholderLabelColor()
if self.isPlaceholderUppercasedWhenEditing {
placeholderLabel.text = placeholderLabel.text?.capitalized
}
updatePlaceholderTextToNormalState()
guard isPlaceholderAnimated else {
return
}
guard isEmpty else {
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment