I want to test for a tap event within a Core Text CTLineRef
variable. I have a CTLineRef
variable, touchedLine
, that I have retrieved by iterating over the CTLine
s in a frame. Once I have found the string with a hit within its bounds, I retrieve the index of the character in the original string from CTLineGetStringIndexForPosition
.
Supposing now that the string data used to create this is not readily accessible without restructuring a portion of the code, can I retrieve the original NSAttributedString
used to create the CTLineRef
variable touchedLine
from touchedLine
itself---some sort of a CTLineGetAttributedString
function?
Since it is an opaque type, CTLine
should contain the data, but there appears to be no way to retrieve them beyond the listed functions in the Apple documentation. So, briefly, no, there isn't.
(One caveat to keep in mind, which helped me solve my initial problem, is that the coordinate system which you are using for the position with CTLineGetStringIndexForPosition
may be y-flipped relative to the rest of your system---that whole Core Text thing again...)