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.
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];
精彩评论