Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kalle Kod
37 PointsPlaceholder color iOS
How do I change the colour of a UITextField's placeholder text in iOS7? Is it possible?
5 Answers
Derek Medlin
6,151 PointsHonestly I never have tried, I see online that people say its ok but after researching a little i believe this might be better.
if ([self.myTextField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
UIColor *color = [UIColor redColor];
self.myTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Your placeholder text" attributes:@{NSForegroundColorAttributeName: color}];
} else {
NSLog(@"Cannot set placeholder text's color, because deployment target is earlier than iOS 6.0");
// TODO: Add fall-back code to set placeholder color.
}
found at http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color
Derek Medlin
6,151 Points[myTextField setValue:myColor forKeyPath:@"_placeholderLabel.textColor"];
Derek Medlin
6,151 PointsActually if you look at the reply under the best answer you will see Sam Soffes (our tree house teacher from the Photo Bombers app) has his own class (SSTextField) that does this for you. BTW the above code is iOS6+
Kalle Kod
37 PointsThanks. Is it a non-private method? I don't want the app to get rejected:)
Kalle Kod
37 PointsGracias!! :)
Derek Medlin
6,151 PointsYou're very welcome. I learned something as well!