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]];
网友评论