将光标移动到UITextField的开头 [英] Moving the cursor to the beginning of UITextField

查看:269
本文介绍了将光标移动到UITextField的开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让光标位于UITextField的开头?

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 like to move it to the beginning.

推荐答案

UITextField 符合 UITextInput 协议,该协议提供允许您控制所选范围的方法。这适用于我的测试:

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];
}

这篇关于将光标移动到UITextField的开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆