Closed m-junaid-butt closed 6 years ago
Hi, Thanks for reporting. I will take a look and try to fix ASAP.
@m-junaid-butt Tell me, please, have you updated the library to the latest version?
@oleghnidets actually, I forked your repo and made my own changes to achieve that behaviour. Let me change my PodFile to point your updated repo. ๐
To be honest, I cannot reproduce the issue. Please, download sample project, launch it. Tap Confirm
button.
Actually, it sets correct placeholder position.
@oleghnidets you are right. It is working in new version. Actually, you forgot to mention the pod version in ReadME file. By default, pod was pointing to 1.0.0 version instead of 1.1.1 that's why I was getting this issue. :(
Please update it in the ReadMe file and then close this issue. Thank you so much to quickly respond my issue. :)
@m-junaid-butt Actually you don't have to specify pod version :) You have to use pod update
.
Read guide for more details.
Hi @oleghnidets, was this issue fixed? I am using version 1.2.2 and I am still getting the described issue: Setting text on the field programatically in viewDidLoad causes the placeholder label to overlay the text.
public override func viewDidLoad() {
super.viewDidLoad()
...
countryField.text = countryCode
}
Do note that my controller is initialised programatically, and the textfield is loaded through the loadView
function.
Upon further inspection of the code, I noticed that minimizePlaceholder
is being called, however since we set the text in viewDidLoad
the frame is still 0. The current workaround is to set the text from viewDidAppear
.
Hi, Take a look, please, at #15 It is a newer version. I will post the update asap.
Now minimizePlaceholder
is called only when a user taps on a text field. Although if you want to make the text field first responder you have to do it in viewDidAppear
.
@oleghnidets In
open class TweePlaceholderTextField: UITextField
When text is set:
open override var text: String? {
didSet {
setCorrectPlaceholderSize()
}
}
which invokes:
@objc private func setCorrectPlaceholderSize() {
if let text = text, text.isEmpty == false {
minimizePlaceholder()
} else if isEditing == false {
maximizePlaceholder()
}
}
which then calls minimizePlaceholder
@objc private func minimizePlaceholder() {
bottomConstraint?.constant = -frame.height //<- height is 0
UIView.animate(withDuration: placeholderDuration, delay: 0, options: [.preferredFramesPerSecond30], animations: {
self.layoutIfNeeded()
switch self.minimizationAnimationType {
case .immediately:
self.placeholderLabel.font = self.placeholderLabel.font.withSize(self.minimumPlaceholderFontSize)
case .smoothly:
self.minimizeFontAnimation.start()
}
}, completion: { _ in
self.minimizeFontAnimation.stop()
})
}
Seems like the code in release 1.2.2
does not match the code in the master branch.
Is 1.2.2 the latest release? or am I using an older version?
EDIT: @oleghnidets didn't see the edit. my bad ๐ thanks for the quick reply!
Currently, it is beta version in master. Sorry, because of lack of time, I cannot manage to update the library.
I have a scenario in which I don't have to activate the text field. I have set text in it programatically based on some conditions but now the issue is, this library does not support this thing. When I set text programatically in the text field then placeholder label does not move up. Both text & placeholder text show in the field. It would be a great improvement if you can add this feature in your library.