Swift中给placeholder设置颜色

2016-10-22  本文已影响113人  不是谁的李逍遥

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

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

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

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

这样就可以了试下吧

上一篇 下一篇

猜你喜欢

热点阅读