美文网首页
Swift中给placeholder设置颜色

Swift中给placeholder设置颜色

作者: 不是谁的李逍遥 | 来源:发表于2016-10-22 12:53 被阅读113次

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

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

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

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

这样就可以了试下吧

相关文章

网友评论

      本文标题:Swift中给placeholder设置颜色

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