I want to change the placeholder colour as red when I left the text field as empty (for example...placeholder of first text field will be changed to read while I left the first text field and starting to enter in the second text field..)
Asked
Active
Viewed 93 times
0
-
You might find your answer here: http://stackoverflow.com/questions/1340224/iphone-uitextfield-change-placeholder-text-color – ZeMoon Mar 13 '14 at 13:00
-
You need to use `NSAttributedString`. after validation fails change the color of the string. you can take help from [here](http://stackoverflow.com/questions/20423541/placing-placeholder-in-textfield/20423592#20423592) – Anoop Vaidya Mar 13 '14 at 13:03
1 Answers
0
You need to use NSAttributedString
. after validation fails change the color of the string.
-(void)methodForValidation{
... //code for validation
if(validationFail){
NSMutableAttributedString *attriButedString = [[NSMutableAttributedString alloc]initWithString:yourStringHere"];
[attriButedString addAttribute:NSForegroundColorAttributeName
value:[NSColor redColor]
range:NSMakeRange(0, lengthOfYourString)];
[[self.yourTextField cell] setPlaceholderAttributedString:attriButedString];
}
}

Anoop Vaidya
- 46,283
- 15
- 111
- 140