Change Customize UITextfield placeholder text in XCode

HI
to change the color of UITextfield placeholder text there are three approaches

1. Override the drawPlaceholderInRect:(CGRect)rect 

 - (void) drawPlaceholderInRect🙁CGRect)rect {
    [[UIColor <your color>] setFill];
    [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:10]];
   }
2.Access the private iVar(risky apple might not approve)
 
 
[self.password setValue:[UIColor colorWithRed:(160/255) green:(97/255) blue:(5/255) alpha:1]forKeyPath:@”_placeholderLabel.textColor”];
 

3.Its not a way but a trick put a ui label in the appropriate place and hide it in
– (void)textFieldDidBeginEditing:(UITextField *)textField{
 
switch (textField.tag) {
 
case 0:
 
lblUserName.hidden=YES;
 
break;
 
case 1:
 
lblPassword.hidden=YES;
 
break;
 
 
default:
 
break;
 
}
 
 
}


A pat on the back !!

Leave a Reply

Your email address will not be published. Required fields are marked *