Change UITextField’s placeholder color without subclassing it

The safe way to customize UITextField’s placeholder is subclassing the UITextField and overriding placeholderRectForBounds:, Apple won’t bother you on this one. However, if you want to take the risk, you can try this way:

[self.MyTextField setValue:[UIColor darkGrayColor] forKeyPath:@"_placeholderLabel.textColor"];

Use KVC to access/set UITextField’s protected ivar directly, fast and risky.

Notes

Show