0

请问,如何更改文本字段背景的颜色和占位符的颜色?我看到了这个答案

在堆栈中,更改 bkgrnd 但不清楚在哪里调用它

[UIColor colorWithRed:0.2f green:0.3f blue:0.4f alpha:0.50001f];

我应该覆盖 UITextField.h 吗?在哪里?或者我应该在哪里改变颜色?

并用于更改占位符,但它不起作用! 堆栈,更改持有人

4

2 回答 2

2

您可以覆盖 UITextField 并在 init 方法中执行此操作。但是我强烈建议您在创建 UITextField 之后再做

textField.backgroundColor = [UIColor colorWithRed:0.2f green:0.3f blue:0.4f alpha:0.50001f];
于 2010-12-09T02:30:38.597 回答
1

要更改文本字段的背景:

  yourTextField.backgroundColor = [UIColor yellowColor];

要更改占位符文本颜色:

   [yourTextField setValue:[UIColor blackColor] forKeyPath:@"_placeholderLabel.textColor"];
于 2012-08-23T04:58:23.797 回答