Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a way to prevent the user from moving the cursor in a UITextField? I'd like it to stay at the end of the string.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
574 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is an old question, but I was looking for an answer to the same question, and found a solution.

It is actually quite simple to prevent the user from moving the cursor. Just subclass UITextField and provide the following implementation of caretRectForPosition:

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    return [super caretRectForPosition:self.endOfDocument];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...