修改UITextfield的Placeholder字体的颜色

Posted 阳光1787354782

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修改UITextfield的Placeholder字体的颜色相关的知识,希望对你有一定的参考价值。

- (void)viewDidLoad

{

    [super viewDidLoad];

 

    self.title=@"修改UITextFieldplaceholder字体颜色";

 

    UITextField *textTF=[[UITextField alloc]initWithFrame:CGRectMake(20,130,300,30)];

    textTF.placeholder=@"修改UITextFieldplaceholder字体颜色";

 

//    // 一种方式

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

 

    // 第二种方式

    textTF.attributedPlaceholder=[[NSAttributedString alloc]initWithString:@"修改UITextFieldplaceholder字体颜色" attributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];

 

    [self.view addSubview:textTF];

}

以上是关于修改UITextfield的Placeholder字体的颜色的主要内容,如果未能解决你的问题,请参考以下文章