UITextField placeholder font color white iOS 5?
Asked Answered
R

3

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?

Rectangular answered 8/5, 2012 at 9:37 Comment(0)
W
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]];
}
Wessels answered 8/5, 2012 at 9:52 Comment(3)
When you override, does that mean you have to create a subclass of UITextField? Say, for instance, CustomTextField?Aeronaut
I have this error: <Error>: CGContextSetFillColorWithColor: invalid context 0x0 pls tell me how i can fix it?Publus
[activeView.layer renderInContext:UIGraphicsGetCurrentContext()];Wessels
H
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.

Hoelscher answered 13/4, 2013 at 20:29 Comment(0)
T
0

Quick fix on the syntax:

[[UILabel appearanceWhenContainedIn:[UITextField class], nil] setTextColor:[UIColor darkGrayColor]];
Trifocal answered 7/10, 2014 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.