3

I have used the below code to display a colored placeholder within iOS Textfield. This works fine in iOS 5 and 6. But in iOS 7 a line appears in the middle of the Textfield.

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void) drawPlaceholderInRect:(CGRect)rect {
    [SEARCH_FIELD_FONT_COLOR setFill];
    if (self.placeholderFont) {
        [[self placeholder] drawInRect:rect withFont:SEARCH_FIELD_FONT];
    }else {
        [[self placeholder] drawInRect:rect withFont:self.placeholderFont];
    }
}

@end

enter image description here

jay
  • 3,517
  • 5
  • 26
  • 44

2 Answers2

0

Try with following code for change color of placeholder of textFiled.

[self.myTextField setValue:[UIColor darkGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
iPatel
  • 46,010
  • 16
  • 115
  • 137
0

This could work a bit better. Also, you can change the font using and attributed placeholder.

- (void) drawPlaceholderInRect:(CGRect)rect {
    [SEARCH_FIELD_FONT_COLOR setFill];

    [super drawPlaceholderInRect:rect];
}
Sulthan
  • 128,090
  • 22
  • 218
  • 270