Commit 87baa186 by Daniel Dahan Committed by GitHub

Merge pull request #715 from mjgaylord/development

Uppercase placeholder in TextField when active
parents 9dc1261d eb9f06fa
...@@ -184,7 +184,11 @@ open class TextField: UITextField { ...@@ -184,7 +184,11 @@ open class TextField: UITextField {
return placeholderLabel.text return placeholderLabel.text
} }
set(value) { set(value) {
if isEditing && isPlaceholderUppercasedWhenEditing {
placeholderLabel.text = value?.uppercased()
} else {
placeholderLabel.text = value placeholderLabel.text = value
}
layoutSubviews() layoutSubviews()
} }
} }
...@@ -353,7 +357,6 @@ open class TextField: UITextField { ...@@ -353,7 +357,6 @@ open class TextField: UITextField {
open var isVisibilityIconButtonAutoHandled = true { open var isVisibilityIconButtonAutoHandled = true {
didSet { didSet {
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside) visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside)
guard isVisibilityIconButtonAutoHandled else { guard isVisibilityIconButtonAutoHandled else {
return return
} }
...@@ -362,6 +365,13 @@ open class TextField: UITextField { ...@@ -362,6 +365,13 @@ open class TextField: UITextField {
} }
} }
@IBInspectable
open var isPlaceholderUppercasedWhenEditing: Bool = false {
didSet {
placeholder = placeholder?.uppercased()
}
}
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -638,10 +648,16 @@ extension TextField { ...@@ -638,10 +648,16 @@ extension TextField {
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
guard isPlaceholderAnimated else { guard isPlaceholderAnimated else {
if isPlaceholderUppercasedWhenEditing {
placeholderLabel.text = placeholderLabel.text?.uppercased()
}
return return
} }
guard isEmpty else { guard isEmpty else {
if isPlaceholderUppercasedWhenEditing {
placeholderLabel.text = placeholderLabel.text?.uppercased()
}
return return
} }
...@@ -651,6 +667,9 @@ extension TextField { ...@@ -651,6 +667,9 @@ 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()
}
switch s.textAlignment { switch s.textAlignment {
case .left, .natural: case .left, .natural:
...@@ -672,11 +691,12 @@ extension TextField { ...@@ -672,11 +691,12 @@ extension TextField {
} }
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
if self.isPlaceholderUppercasedWhenEditing {
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