ios4 - iPhone CoreText: Find the pixel coordinates of a substring -


There is a screenshot of the Twitter app for reference:

What I want to do is a temporary place A NSAttributedString is a requirement for the NSAttributedString project which can run multiple lines of pop-over at the top of a substring.

In the given screenshot, you can see that links are background-highlighted, so it leads me to believe that they are using CoreText and NSAttributedStrings. I got something called CTRunerf () that looked promising, but I am having trouble fixing it all together, perceptually.

In short, if I have a paragraph in the original text and when I tap on a word, how can I find the bounding box for that word?

Set some attributes in the desired string which will not affect the display, but it will have different glyph runs , Then use the core text to move the layout string

  CTFramesetterRef frameset = CTFramesetterCreateWithAttributedString (attrString); CTFrameRef ctframe = CTFramesetterCreateFrame (frameset, cfrangemake (0, 0), path, zero);  

Now you have to hunt through the frame to find the relevant part of the text. Get an array of CTFRM gateline () with CTLineRef s.

Repeat through the array, if the test was touched on that row, check it within the rectangle returned by CTLineGetImageBounds () . If so, then now the glyph runs in the line.

Again, you can get the CTRunRef s with CTLineGetGlyphRuns () . Check whether the tap was inside the glyph with CTRunGetImageBounds () , and if you can find the range of index in the original desired string, that glyph run to CTRunGetStringIndices) .


Comments