How to change placeholder text color in xib ? I have tried key path thing but it is giving me NSException. Can anyone please help.
Asked
Active
Viewed 2.1k times
20
-
try this http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color – Naga Mallesh Maddali Apr 25 '14 at 05:16
-
i just want to change my textfield placeholder color. As my textfield background color is gray due to which placeholder is not visible. so i want my placeholder to be black in color. – goCode Apr 25 '14 at 05:58
4 Answers
59
The easiest method to modify the placeholder text color is through the Xcode storyboard interface builder. Select the UITextField of interest and open the identity inspector on the right. Click on the plus symbol in the User Defined Runtime Attributes and add a new row with Key Path as placeholderLabel.textColor
, Type as Color and Value to your desired color.

snibbe
- 2,715
- 1
- 27
- 34

Navneil Naicker
- 3,586
- 2
- 21
- 31
-
1Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath. – goCode Apr 25 '14 at 05:20 -
You can also try this answer [stackoverflow](http://stackoverflow.com/questions/18584587/how-to-set-the-color-of-the-place-holder-text-for-a-uitextfield-while-preserving) – Navneil Naicker Apr 25 '14 at 05:22
-
Failed to set (_placeholderLabel.textColor,) user defined inspected property on (UITextField): [
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key textColor,. – apinho Oct 14 '16 at 09:35 -
1
-
3This is a great solution as it allows you to select colors from the color assets library. I am on Swift 5, Xcode 11 and iOS 13. The key for me to use was `placeholderLabel.textColor` without the underscore. – Bocaxica Oct 03 '19 at 12:02
-
How to Set this globally? I mean for all textFields in my Project – wajahat akram Jul 08 '23 at 08:10
-
The problem is it only works if I add some default text into placeholder, otherwise not working – wajahat akram Jul 10 '23 at 06:45
4
We cannot change textcolor of placeholder text in storyboard. Manually we can change with the property name.
Addthis code in viewDidLoad
[nameTextField setValue:[UIColor colorWithRed:41.0/255.0 green:91.0/255.0 blue:106.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];

Mihir Oza
- 2,768
- 3
- 35
- 61

Uma Madhavi
- 4,851
- 5
- 38
- 73