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 { ...@@ -366,9 +366,9 @@ open class TextField: UITextField {
} }
@IBInspectable @IBInspectable
open var isPlaceholderUppercasedWhenEditing: Bool = false { open var isPlaceholderUppercasedWhenEditing = false {
didSet { didSet {
placeholder = placeholder?.uppercased() updatePlaceholderTextToActiveState()
} }
} }
...@@ -503,6 +503,32 @@ fileprivate extension TextField { ...@@ -503,6 +503,32 @@ fileprivate extension TextField {
placeholderLabel.textColor = isEditing ? placeholderActiveColor : placeholderNormalColor 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. /// Updates the detailLabel text color.
func updateDetailLabelColor() { func updateDetailLabelColor() {
detailLabel.textColor = detailColor detailLabel.textColor = detailColor
...@@ -648,16 +674,12 @@ extension TextField { ...@@ -648,16 +674,12 @@ extension TextField {
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
guard isPlaceholderAnimated else { guard isPlaceholderAnimated else {
if isPlaceholderUppercasedWhenEditing { updatePlaceholderTextToActiveState()
placeholderLabel.text = placeholderLabel.text?.uppercased()
}
return return
} }
guard isEmpty else { guard isEmpty else {
if isPlaceholderUppercasedWhenEditing { updatePlaceholderTextToActiveState()
placeholderLabel.text = placeholderLabel.text?.uppercased()
}
return return
} }
...@@ -667,9 +689,8 @@ extension TextField { ...@@ -667,9 +689,8 @@ extension TextField {
} }
s.placeholderLabel.transform = CGAffineTransform(scaleX: s.placeholderActiveScale, y: s.placeholderActiveScale) 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 { switch s.textAlignment {
case .left, .natural: case .left, .natural:
...@@ -691,12 +712,12 @@ extension TextField { ...@@ -691,12 +712,12 @@ extension TextField {
} }
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
if self.isPlaceholderUppercasedWhenEditing { updatePlaceholderTextToNormalState()
placeholderLabel.text = placeholderLabel.text?.capitalized
}
guard isPlaceholderAnimated else { guard isPlaceholderAnimated else {
return return
} }
guard isEmpty else { guard isEmpty else {
return 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