iPhone UITextField - Change placeholder text color iPhone UITextField - Change placeholder text color ios ios

iPhone UITextField - Change placeholder text color


Since the introduction of attributed strings in UIViews in iOS 6, it's possible to assign a color to the placeholder text like this:

if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)]) {  UIColor *color = [UIColor blackColor];  textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholderText attributes:@{NSForegroundColorAttributeName: color}];} else {  NSLog(@"Cannot set placeholder text's color, because deployment target is earlier than iOS 6.0");  // TODO: Add fall-back code to set placeholder color.}


Easy and pain-free, could be an easy alternative for some.

_placeholderLabel.textColor

Not suggested for production, Apple may reject your submission.


You can override drawPlaceholderInRect:(CGRect)rect as such to manually render the placeholder text:

- (void) drawPlaceholderInRect:(CGRect)rect {    [[UIColor blueColor] setFill];    [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];}