修改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];

}

posted @ 2016-06-23 09:44  yhj1787354782  阅读(152)  评论(0编辑  收藏  举报