I’m trying to display an UIPopoverController from the rect of a selected text in an UITextView, How can I get the selected text CGRect ?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think
[UITextInput selectedTextRange]and[UITextInput caretRectForPosition:]is what you are looking for.[UITextInput selectedTextRange]returns the selected range in character[UITextInput caretRectForPosition:]returns theCGRectof the character range in this input.UITextViewconforms toUITextInput(since iOS 5), so you can use these methods for yourUITextViewinstance.It is going to be something like this.
EDIT : Since the sample code became a little hard to get, I added an image for complementing.