Swift中给placeholder设置颜色

在OC中给placeholder设置颜色可以直接用KVC

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

但是在swift中这么写直接崩掉
所以找了另一种方法

 let str = NSAttributedString(string: "输入手机号", attributes: [NSForegroundColorAttributeName:UIColor.white])
 phoneNumer.attributedPlaceholder = str

这样就可以了试下吧

你可能感兴趣的:(Swift中给placeholder设置颜色)