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

Hide placeholder on focus #286

Open toseefkhilji opened 5 years ago

toseefkhilji commented 5 years ago

I am trying to show title text and hide placeholder on focus of text field.

Is there any workaround on this problem?

Thanks...

artuc commented 5 years ago

Subclassing SkyFloatingLabelTextField and implementing these methods solved it for me

    override func becomeFirstResponder() -> Bool {
        if !hasText {
            placeholder = ""
        }
        setTitleVisible(true)
        return super.becomeFirstResponder()
    }

    override func resignFirstResponder() -> Bool {
        if !hasText {
            placeholder = title
        }
        setTitleVisible(hasText || hasErrorMessage)
        return super.resignFirstResponder()
    }