I have a custom UITextField
so that I get get a custom placeholder text color as may answers suggest. However, I also want to change the color of the placeholder text at runtime, so I created a property.
// Overide the placholder text color
- (void) drawPlaceholderInRect:(CGRect)rect
{
[self.placeholderTextColor setFill];
[self.placeholder drawInRect:rect
withFont:self.font
lineBreakMode:UILineBreakModeTailTruncation
alignment:self.textAlignment];
}
- (void) setPlaceholderTextColor:(UIColor *)placeholderTextColor
{
// To verify this is being called and that the placeholder property is set
NSLog(@"placeholder text: %@", self.placeholder);
_placeholderTextColor = placeholderTextColor;
[self setNeedsDisplay]; // This does not trigger drawPlaceholderInRect
}
The problem is the docs say I should not call drawPlaceholderInRect directly, and [self setNeedsDisplay];
dons't work. Any ideas?