方法一
NSMutableAttributedString * placehoder= [[NSMutableAttributedString alloc]initWithString:@"手机号"];
[placehoder setAttributes:@{NSForegroundColorAttributeName :[UIColor whiteColor]} range:NSMakeRange(1, 1)];
self.phoneField.attributedPlaceholder = placehoder;
方法二
//通过这个方法重写placeholder
- (void)drawPlaceholderInRect:(CGRect)rect
{
[self.placeholder drawInRect:CGRectMake(0, 10, rect.size.width, 25) withAttributes:@{
NSForegroundColorAttributeName :[UIColor grayColor], NSFontAttributeName:self.font}];
}
方法三使用kvc
static NSString * const LJHplaceholderColor = @"_placeholderLabel.textColor";
@implementation TextFieldWhite
- (void)awakeFromNib
{
self.tintColor = self.textColor;
[self resignFirstResponder];
}
- (BOOL)becomeFirstResponder
{
[self setValue:[UIColor whiteColor] forKeyPath:LJHplaceholderColor];
return [super becomeFirstResponder];
}
- (BOOL)resignFirstResponder
{
[self setValue:self.textColor forKeyPath:LJHplaceholderColor];
return [super resignFirstResponder];
}