美文网首页
UITextField改变placeholder样式

UITextField改变placeholder样式

作者: 倪大头 | 来源:发表于2018-11-29 16:00 被阅读5次
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor redColor];
UITextField *textField = [[UITextField alloc]init];
textField.attributedPlaceholder = [[NSMutableAttributedString alloc]initWithString:@"请输入内容" attributes:attrs];

还有一个更省力的方法:

[textField setValue:[UIColor yellowColor] forKeyPath:@"_placeholderLabel.textColor"];

[textField setValue:[UIFont systemFontOfSize:17] forKeyPath:@"_placeholderLabel.font"];

改变光标颜色(此方法影响所有TextField):

[[UITextField appearance] setTintColor:[UIColor blackColor]];  

相关文章

网友评论

      本文标题:UITextField改变placeholder样式

      本文链接:https://www.haomeiwen.com/subject/vosfcqtx.html