How do I subclass UITextField and override drawPlaceholderInRect to change Placeholder color How do I subclass UITextField and override drawPlaceholderInRect to change Placeholder color ios ios

How do I subclass UITextField and override drawPlaceholderInRect to change Placeholder color


To answer you specific question, this is how subclassing works:

// CustomTextField.h@interface CustomTextField : UITextField {}@end

Here's how to override the method:

@implementation- (CGRect)placeholderRectForBounds:(CGRect)bounds {    return CGRectMake(x,y,width,height);}@end

However I don't think that's the method you want to override. I think this is what you're looking for:

@implementation- (void)drawPlaceholderInRect:(CGRect)rect {    // Your drawing code.}@end


[yourTextfield setValue:[UIColor colorWithRed:62.0/255.0f green:62.0/255.0f blue:62./255.0f alpha:1.0f]  forKeyPath:@"_placeholderLabel.textColor"];

I guess this would be helpful