修改UITextField的placehold的文字颜色

注:阅读了xx_cc 写的文章来摘录笔记
修改placeHoldLabel的文字颜色有三种方法
1.使用富文本修改占位文字颜色

NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
attributes[NSForegroundColorAttributeName] = [UIColor whiteColor];
self.attributedPlaceholder = [[NSAttributedString alloc]initWithString:self.placeholder attributes:attributes];

2.直接修改内部占位文字Label的文字颜色

[self setValue:[UIColor grayColor] forKeyPath:@"placeholderLabel.textColor"];

3.通过重写drawRect方法来重绘站位文字并修改站位文字颜色

-(void)drawPlaceholderInRect:(CGRect)rect{ 
NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; 
attributes[NSFontAttributeName] = self.font; attributes[NSForegroundColorAttributeName] = [UIColor whiteColor]; 
// 从一个起点开始绘画 
CGPoint placeholderPoint = CGPointMake(0, (self.cl_height - self.font.lineHeight)*0.5); 
[self.placeholder drawAtPoint:placeholderPoint withAttributes:attributes]; 
// 画到一个范围
// self.placeholder drawInRect:<#(CGRect)#> withAttributes:<#(nullable NSDictionary *)#>
}

你可能感兴趣的:(修改UITextField的placehold的文字颜色)