Abhinav
Abhinav

Reputation: 38142

Auto selection of text in textfield on tap

In my application, I have a textbox which is very small. I want to highlight the text in it once user tap in it so then on typing next character, previous text (highlighted on tap) goes away and newly entered data replaces it.

I have tried with following code:

UITextField *aTextField = [[UITextField alloc] initWithFrame:myFrame];
aTextField.clearButtonMode = UITextFieldViewModeWhileEditing;

But since textfield is very small, this does not suit here. I want to hightlight the text on tap without any control showing up and then on tap of next character I will replace the highlighted text. Any idea how to do this.

Upvotes: 3

Views: 4923

Answers (1)

Rob Napier
Rob Napier

Reputation: 299275

You want to use the UIResponderStandardEditActions category on UITextField. This is not a surprising thing to overlook; it's somewhat buried in the docs.

[self.textField selectAll:nil];

Upvotes: 10

Related Questions