Romula Romula - 1 year ago 132
iOS Question

UITextField set cursor to start text position

I need to move cursor to start text position on set focus on the textfield. Is it possible tot do?

omz omz
Answer Source

Set your view controller (or some other appropriate object) as the text field's delegate and implement the textFieldDidBeginEditing: method like this:

- (void)textFieldDidBeginEditing:(UITextField *)textField
    UITextPosition *beginning = [textField beginningOfDocument];
    [textField setSelectedTextRange:[textField textRangeFromPosition:beginning

Note that setSelectedTextRange: is a protocol method of UITextInput (which UITextField implements), so you won't find it directly in the UITextField documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download