views:

47

answers:

1

I am looking for a non private way to find the position of the Cursor or Caret (blinking bar) in a UITextView preferably as a CGPoint.

There may be a question like this already but it does not provide a definitive way for doing it. And, I do not mean the NSRange of the selected area.

+2  A: 

There is no such way. Full stop.

The only thing you could do to come close is to in parallel lay out the text using CoreText, there calcualte the text position from a point and apply that on the UITextView. This, however, works with non-0 selections only. In addition CoreText has a different text layout engine, that e.g. supports kerning, which UITextView doesn't. This may result in deviations of the rendered and laid out text and thus give sub-optimal results.

There is absolutely no way to position the caret. This task is even very though if you do use private API. It's just one of the many "just don't" in iOS.

Max Seelemann
So there's absolutely no way to calculate the position of the caret?
Joshua
Nope. Not with UITextView. As I said: you can lay the text out a second time using CoreText and calculate the position there, but that gives you estimates at best.
Max Seelemann