I asked a developer (TwoLivesLeft, the creators of Codea) how they did syntax highlighting in their app. He replied :
@TD2 the Codea editor is implemented using a UITextView. The
highlighting is done by overlaying subviews in the appropriate
positions — usually UILabels. They are dequeued from a re-use pool,
similar to the way UITableViewCells work. During scrolling, the lines
requiring re-highlighting pull markers out of the pool and lines that
have moved off screen dump their markers back into the pool.
Can anyone explain how I would get the x and y of a certain word?
UITextView conforms to UITextInput, of which a detailed description can be found here.
Take a look at the required methods “textRangeFromPosition:toPosition:”, “positionFromPosition:offset:”, “positionFromPosition:inDirection:offset:”, and some of the other geometric-based methods in the UITextInput Protocol. Those might provide the functionality you are looking for.
I have not actually tried to make sure these work the way you want them too, but that looks like its about what you need.
Let me know if you need any more help!
UPDATE:
Here is some sample code of how to do this. I ended up getting the “firstRectForRange:” method to work. This code basically takes the last three letters of the UITextView “textStuff” and highlights it green.
Result of running this code: