GB540
GB540

Reputation: 121

Moving UITextView cursor to a CGPoint

Am trying to make a UITextView behave the way the one in Notes does, i.e. you tap to make it editable (turning off the data detectors) then the cursor moves to where you tapped.

Got the tap-to-edit part working with a UITapGestureRecognizer, but how on earth do you translate the tap's CGPoint into a NSRange for moving the cursor?

I don't have the luxury of doing this under 5.0 (no UITextInput for the UITextView, ack). Also needs to be public API's, no private stuff.

Thanks in advance. :)

Upvotes: 1

Views: 1627

Answers (1)

PeakJi
PeakJi

Reputation: 1547

UITextPosition * position=[textView closestPositionToPoint:CGPointMake(20, 20)];
[textView setSelectedTextRange:[textView textRangeFromPosition:position toPosition:position]];

Upvotes: 3

Related Questions