Change default text and color when text box is selected

I was wondering if it is possible to change the default text in the textbox in the xib file when the field is selected.

For example, the placeholder would be "Phone number" in gray, and then after the user selects the field, it changes to "+44" in black?

Thank,

Feras

+3


source to share


1 answer


This should be achieved by changing the text attribute in the didBeginEditing function of the UITextField delegate as follows:



extension YourClass : UITextFieldDelegate {
    func textFieldDidBeginEditing(_ textField: UITextField) {
        textField.text = "+44"
    }
}

      

+4


source







All Articles