How do I change the placeholder text color of a UITextField through Swift? I can't seem to access the placeholder attribute. Thanks
You can set the placeholder text using an Attributed string. Set color to attributes
Property.
textField.attributedPlaceholder = NSAttributedString(string:"placeholder text",
attributes:[NSForegroundColorAttributeName: UIColor.yellowColor()])
Swift 5
textField.attributedPlaceholder = NSAttributedString(string:"placeholder text", attributes:[NSAttributedString.Key.foregroundColor: UIColor.yellow])
Click on the + button and add a new runtime attribute: _placeholderLabel.textColor
Run your app.
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