Prevent user from setting cursor position on UITextField

后端 未结 6 963
执念已碎
执念已碎 2020-12-17 17:03

I have an UITextField constructed using the storyboard. I want to not allow the user to change the position of the cursor and keep it always at the end of the text into the

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 17:30

    Ok, what you have to do is have a UITextField that is hidden.

    Add that hidden text field to the view, and call becomeFirstResponder on it. From your amountBoxTouchDown: method.

    In the Textfield delegate, take the text the user typed in and add it to amountBox.text. Also turn off userInteractionEnabled for the visible amountBox textField.

    This creates the effect you desire.

    Have a look at for some sample code Link.

提交回复
热议问题