如何更改UITextField 的placeholder 的字体颜色

storyboard 中这样设置

具体步骤:

1.在User Defined Runtime Attributes中添加一个Key。

2.输入Key Path(这里我们输入_placeholderLabel.textColor)。

3.选择Type,有很多种(这里我们选择Color)

 
4.设置Value(这里出现的是颜色的选择面板,选择想要的颜色即可)。
 
 
纯代码的话这样子就 OK 啦
//textField的placeholder的背景色更改第一种颜色
    _userNameTxf.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
    //第二种方法
    [_userNameTxf setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel..textColor"];
posted @ 2016-04-08 13:29  渣渣你好  阅读(188)  评论(0编辑  收藏  举报