Getting cursor position in a UITextView on the iPhone?

后端 未结 4 1441
一向
一向 2020-12-24 03:23

We have a UITextView in our iPhone app which is editable. We need to insert some text at the cursor location when the users presses some toolbar buttons but can\'t seem to

4条回答
  •  别那么骄傲
    2020-12-24 03:54

    Use UITextView selectedRange property to find the insertion point when the text view is first responder. Otherwise, when the view is not in focus, this property returns NSNotFound. If you need to know the cursor position in that case, consider subclassing UITextView and overriding canResignFirstResponder method, where you can store cursor position to a member variable.

提交回复
热议问题