FerasAS
FerasAS

Reputation: 293

Changing default Text and colour on selection of text field

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

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

Thanks,

Feras

Upvotes: 4

Views: 841

Answers (1)

Maroš Beťko
Maroš Beťko

Reputation: 2329

This should be achievable by changing text attribute in didBeginEditing function of the UITextField's delegate like this:

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

Upvotes: 5

Related Questions