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?
Solution #1 - If you want the placeholder to disappear as soon as the user selects the text view: First set the UITextView to contain the placeholder text and set it to a light gray color to mimic the look of a UITextField 's placeholder text. Either do so in the viewDidLoad or upon the text view's creation.
Create UITextField Extension like this: extension UITextField{ @IBInspectable var placeHolderColor: UIColor? { get { return self. placeHolderColor } set { self. attributedPlaceholder = NSAttributedString(string:self.
Type placeholders is a new language feature introduced in Swift 5.6 (Xcode 13.3). The concept is straightforward. Type placeholders allow us to write types with type placeholders ( _ ) which directs the compiler to infer the type where _ is used.
The string that displays when there is no other text in the text field.
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
Swift 3
If your textField has text, you need to first set text property to nil, then set placeholder text:
textField.text = nil textField.placeholder = "My Placeholder Text"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With