Joe Sloan Joe Sloan - 2 years ago 546
Swift Question

Add Placeholder to UITextField, how to set the placeholder text programmatically in swift?

I'm pulling out a phone number from a database, and when the user begins editing in the text field to change that phone number I'd like to use the number I currently have in the database as the placeholder. Since this information changes with each user, how can I set it programmatically in swift?

Answer Source

You need to get the phone number from your database first (convert them to String), then you set placeholder of your textField to that String, like so

 textField.placeholder = phoneNumberString
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download