Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear UITextField Placeholder text on tap

Tags:

In Xcode4 I've created some placeholder text for a UITextField and I'd like it to clear when the user taps in the box.

So, in the Attributes Inspector for the text field I've clicked "Clear when editing begins" however this does not immediately remove the text when I tap in the text box (it only disappears when you start typing).

Is there any way of removing the placeholder text immediately on tapping in the text box?

like image 809
Snowcrash Avatar asked Dec 16 '11 10:12

Snowcrash


1 Answers

make your ViewController the delegate of the textField and implement those two methods:

- (void)textFieldDidBeginEditing:(UITextField *)textField {     textField.placeholder = nil; }  - (void)textFieldDidEndEditing:(UITextField *)textField {     textField.placeholder = @"Your Placeholdertext"; } 
like image 57
Matthias Bauch Avatar answered Sep 30 '22 15:09

Matthias Bauch