-1

I'm trying to set the placeholder color in a UITextfield to white color but it doesn't seem to work. please help. It triend this line of code:

UIColor *color = [UIColor WhiteColor];
emailBox.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Enter your email address" attributes:@{NSForegroundColorAttributeName: color}];
Abdelilah
  • 51
  • 4
  • 2
    Could it be that `emailBox` is nil? – matt Jun 03 '15 at 14:36
  • What is `WhiteColor`? Is this your real code? Please do not type code by hand. Copy it from your real, compilable project, and _paste_ it into Stack Overflow. We cannot help you if you lie about what your code is. – matt Jun 03 '15 at 14:38
  • Mate it's a typo, not a lie – Jef Jun 03 '15 at 20:58
  • I think you ought reconsider this design, making placeholder text a solid colour may confuse the user about intent. I don't know if this is covered in the interface guidelines but clearly Apple have not made any effort to allow you to set this colour so perhaps they don't want you to. – Jef Jun 03 '15 at 21:03

1 Answers1

0

Maybe this is connected to this answered issue, the solution is to check the context in which you are setting the attributedPlaceholder.

Maybe you are doing it in viewDidLoad?

Try doing it when the user begins to enter text. In textField:shouldChangeCharactersInRange:

Community
  • 1
  • 1
Sajjon
  • 8,938
  • 5
  • 60
  • 94