Closed lawgimenez closed 6 years ago
Hey @lawgimenez ,
just set the titleFormatter
to a function that does not modify the title and you're good
I didn't like it too. That's why I've changed the "needToUpperCasePlaceholder" function and added "needToUpperCasePlaceholder" variable:
@IBInspectable dynamic open var needToUpperCasePlaceholder: Bool = false {
didSet {
}
}
open var titleFormatter: ((Bool, String) -> String) = { (needToUpperCasePlaceholder: Bool, text: String) -> String in
return needToUpperCasePlaceholder ? text.uppercased() : text
}
When I changed it I had to change the "updateTitleLabel", "titleOrPlaceholder" and "selectedTitleOrTitlePlaceholder" functions:
fileprivate func updateTitleLabel(_ animated: Bool = false) {
var titleText: String? = nil
if hasErrorMessage {
titleText = titleFormatter(false, errorMessage!)
} else {
if editingOrSelected {
titleText = selectedTitleOrTitlePlaceholder()
if titleText == nil {
titleText = titleOrPlaceholder()
}
} else {
titleText = titleOrPlaceholder()
}
}
titleLabel.text = titleText
updateTitleVisibility(animated)
}
fileprivate func titleOrPlaceholder() -> String? {
guard let title = title ?? placeholder else {
return nil
}
return titleFormatter(needToUpperCasePlaceholder, title)
}
fileprivate func selectedTitleOrTitlePlaceholder() -> String? {
guard let title = selectedTitle ?? title ?? placeholder else {
return nil
}
return titleFormatter(needToUpperCasePlaceholder, title)
}
Like @k0nserv suggested, we can use titleFormatter
:
self.password.titleFormatter = { (text: String) in return text }
@lawgimenez set the formatter like this
textField.titleFormatter = { $0 }
Worth noting - this needs to be set before the title itself is set, otherwise the titleFormatter
block doesn't get called. 🚀
Report
What did you do?
ℹ I implemented this library and I want an option where the title would not be in all caps
What did you expect to happen?
ℹ Title to not be in all caps option
What happened instead?
ℹ Can't find an option for disabling all caps in title
Environment
ℹ Please fill in this section with information about your environment
Xcode Version: 9.2 SkyFloatingLabelTextField Version: 3.4.0 Deployment Target: 11.2 Base SDK: 11.2 Method of Integration: CocoaPods
Project that demonstrates the issue
ℹ Please link to a project we can download that reproduces the issue if applicable.