I want to insert a UITextField in between the text of a UITextView to provide “fill in the blanks” functionality. I know that UITextField can’t be added to the UITextView so I want to add UITextField to the super view of the UITextView by maintaining space for these UITextFields on the UITextView.
How can I determine the coordinates of a particular character with respect to the origin of the UITextView? The frame of the textView and its super view are the same. Can any one please tell me how to do this? Is there any other way to achieve fill in the blanks functionality with in a paragraph of text?
You may be able to use the UIStringDrawing additions to the NSString class to help find the location of characters.
If the character you are looking for is on the first line of the text view,
sizeOfStringwill give you the coordinates (offset by the line height).If the character you are looking for is not on the first line, you would need to iteratively determine the location of each character up to the character you are looking for, modifying the substring to remove previous lines of text each time you detect the end of a line. You can detect the end of a line by noting when the
sizeOfString‘s height has changed between iterations.