富文本方法
@property (weak, nonatomic) IBOutlet UITextField *textField;
NSDictionary *dic = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:15]};
self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Hello_Wrold!" attributes:dic];
self.textField.tintColor = [UIColor cyanColor];
KVC方法
self.textField.placeholder = @"Hello_Wrold!";
[self.textField setValue:[UIColor magentaColor] forKeyPath:@"_placeholderLabel.textColor"]
[self.textField setValue:[UIFont systemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
self.textField.tintColor = [UIColor greenColor];
本文介绍如何使用富文本方法和KVC方法来设置 UITextField 的占位符颜色和字体大小,包括通过属性列表设置字体颜色及大小,以及利用 KVC 设置文本框样式。
2万+

被折叠的 条评论
为什么被折叠?



