Moving the cursor to the beginning of UITextField

前端 未结 3 1721
深忆病人
深忆病人 2020-11-29 13:17

Is there a way to make the cursor be at the start of a UITextField?

When I display the control with content, the cursor is placed at the end of the string. I\'d lik

3条回答
  •  伪装坚强ぢ
    2020-11-29 13:54

    UITextField conforms to the UITextInput protocol, which provides methods that let you control the selected range. This works in my testing:

    -(void)textFieldDidBeginEditing:(UITextField *)textField {
        textField.selectedTextRange = [textField
            textRangeFromPosition:textField.beginningOfDocument
            toPosition:textField.beginningOfDocument];
    }
    

提交回复
热议问题