Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my UITextField Placeholder disappear when setting UITextField background to .clearColor?

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

like image 398
20man Avatar asked Dec 04 '25 23:12

20man


1 Answers

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"];
like image 177
Bhoomi Jagani Avatar answered Dec 07 '25 16:12

Bhoomi Jagani