1

I have a problem in a XIB. The color of my placeholder color is default gray in interface builder but when i run the app the color of the text i white, and I'cant see it because the background is white.

Does anyone have a solution to this?

johan
  • 6,578
  • 6
  • 46
  • 68

3 Answers3

5

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

- (void) drawPlaceholderInRect:(CGRect)rect {
    [[UIColor blueColor] setFill];
    [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}
Venk
  • 5,949
  • 9
  • 41
  • 52
Aseem
  • 174
  • 2
  • 10
  • When you override, does that mean you have to create a subclass of `UITextField`? Say, for instance, `CustomTextField`? – James Oct 05 '12 at 17:08
  • I have this error: : CGContextSetFillColorWithColor: invalid context 0x0 pls tell me how i can fix it? – Bimawa Jul 11 '13 at 11:34
  • [activeView.layer renderInContext:UIGraphicsGetCurrentContext()]; – Aseem Aug 17 '13 at 10:40
1

The above solution did not work for me, I used the following workaround.

[UILabel appearanceWhenContainedIn:[UITextField class], nil] setTextColor:[UIColor darkGrayColor]];

But then I got to know another bug, the above did the job but it also reset the color of all other labels to Default Black. Then I had to sub class the UILabel class and use my class in all other labels in my view.

Jibran K
  • 885
  • 7
  • 20
0

Quick fix on the syntax:

[[UILabel appearanceWhenContainedIn:[UITextField class], nil] setTextColor:[UIColor darkGrayColor]];
exeapps
  • 119
  • 1
  • 4