美文网首页
UITextField设置预显字体颜色

UITextField设置预显字体颜色

作者: 浅_若清风 | 来源:发表于2021-12-17 16:33 被阅读0次

1、在ios13前可直接调用系统自带key值“_placeholderLabel.textColor”设置

textField.placeholder =@"输入密码";
[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

2、ios13以及之后版本,直接使用“_placeholderLabel.textColor”会崩溃,可以使用富文本实现,颜色对应key参数是NSForegroundColorAttributeName

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.minimumLineHeight = 0;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString@"输入密码" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13], NSParagraphStyleAttributeName : style,NSForegroundColorAttributeName:[UIColor whiteColor]}];
textField.attributedPlaceholder = attributedString;

相关文章

网友评论

      本文标题:UITextField设置预显字体颜色

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