Uffo
Uffo

Reputation: 10056

iOS text field doesn't show placeholder text

So I have some basic textfields with a custom background, that is a line at the bottom and the rest of it it's transparent, but now the placeholders don't show anymore.

These are the text fields

enter image description here

And config

enter image description here

Upvotes: 2

Views: 3934

Answers (3)

Nicholas H.
Nicholas H.

Reputation: 1311

I had the same problem. Turns out it had nothing to do with me having set borderStyle to UITextBorderStyleNone. It was caused by me subclassing UITextField to add a manually drawn border along the bottom only and failing to call the super implementation in my override of layoutSubviews. Once I had sorted that, my placeholder text was back.

Upvotes: 1

Joseph El Khoury
Joseph El Khoury

Reputation: 516

It's better to do this:

if ([self.textField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
    self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}

Upvotes: 1

Uffo
Uffo

Reputation: 10056

I have found a solution that works, you need to select the input and set the following on User Defined Runtime Attributes

enter image description here

Upvotes: 2

Related Questions