iOS修改textField的placeholder的字体颜色

来源:互联网 发布:openjdk8源码下载 编辑:程序博客网 时间:2024/05/19 10:12

一、iOS6.0以后提供的方法为self.textField.attributedPlaceholder = attrString;提供可变字符串就行。

NSAttributedString *attrString = [[NSAttributedStringalloc] initWithString:@"请输入占位文字" attributes:

                                      @{NSForegroundColorAttributeName:[UIColorcyanColor],

                                        NSFontAttributeName:self.textField.font

                                        }];

    self.textField.attributedPlaceholder = attrString;

二、通过KVC修改placeholder的颜色。

[self.textFieldsetValue:[UIColorcyanColor] forKeyPath:@"_placeholderLabel.textColor"];


阅读全文
0 0
原创粉丝点击