Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change placeholder text color on swift

Tags:

ios

swift

How do I change the placeholder text color of a UITextField through Swift? I can't seem to access the placeholder attribute. Thanks

like image 875
user2585611 Avatar asked Dec 29 '14 04:12

user2585611


2 Answers

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])
like image 115
iBhavin Avatar answered Oct 01 '22 07:10

iBhavin


enter image description here

Click on the + button and add a new runtime attribute: _placeholderLabel.textColor

Run your app.

like image 41
Shashi Verma Avatar answered Oct 01 '22 08:10

Shashi Verma