Skyscanner / SkyFloatingLabelTextField

A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.
Apache License 2.0
4.09k stars 540 forks source link

Title is not formatted using titleFormatter initially when Text is defined #253

Open hipwelljo opened 5 years ago

hipwelljo commented 5 years ago

Bug Report

What did you do?

I have added a SkyFloatingLabelTextField to Interface Builder, configured its text, created an IBOutlet, and set its titleFormatter in viewDidLoad. The problem is when you go to this screen the title is not formatted using the provided formatter. If you tap the field to select it then the title changes its format.

A workaround is to remove the Text from the storyboard and set it in code (but only after you set the titleFormatter!).

What did you expect to happen?

The titleFormatter should always be used before the title is displayed

What happened instead?

The titleFormatter is not utilized when Text is defined in Interface Builder

Environment

Xcode Version: 10.1 SkyFloatingLabelTextField Version: 3.6.0 Deployment Target: iOS 12.1 Base SDK: iOS 12.1 Method of Integration: CocoaPods

Project that demonstrates the issue

If needed I can create one, but it's quite simple to recreate the issue.

k0nserv commented 5 years ago

We'd need to update the active title when the titleFormatter changes to support this. If you submit a PR for it we can include it or just set the title from code as a workaround

Jeferson-Oliveira commented 5 years ago

Just set the formatter before set the tittle or placeholder

Use textField.titleFormatter = { texTitle in return title } textField.placeholder = placeholder Instead textField.placeholder = placeholder textField.titleFormatter = { texTitle in return title }