2

Using Xcode v7.2 - iOS v9.2 - iPhone5S Swift

I am trying to create a transparent UITextField, with a light gray placeholder text.

I have used:

self.userEmailTextField.backgroundColor = UIColor.clearColor()

The placeholder text disappears, however it appears when using whiteColor, or blueColor backgrounds.

white background:

userEmailTextField with .whiteColor Background

clear background:

userEmailTextField with .clearColor Background

rmaddy
  • 314,917
  • 42
  • 532
  • 579
20man
  • 23
  • 2
  • 4

2 Answers2

7

Placeholder is not visible due to your clear background color.You can check it by setting palceholder color like this...

In Swift...

if let _ = self.placeholder{
 self.txtField.attributedPlaceholder = NSAttributedString(string:self.placeholder!,
    attributes:[NSForegroundColorAttributeName: UIColor.whiteColor()])
  }

In Objective c...

[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
Bhoomi Jagani
  • 2,413
  • 18
  • 24
5

Placeholder color changes based on the color of textfield. So when you set clear color then it also set placeholder color accordingly. Basically its not disappearing but not visible.

Krishna Kumar
  • 1,652
  • 9
  • 17
  • Makes sense! - your comment led me to this: http://stackoverflow.com/a/22017127/5755562 and problem resolved. – 20man Jan 07 '16 at 09:28
  • Good thought.. My up votes will appear publically once I receive 15 reputation, apparently.. Thanks again – 20man Jan 09 '16 at 07:28