iPhone CoreText: Find the pixel coordinates of a substring

后端 未结 4 1669
故里飘歌
故里飘歌 2021-01-30 19:09

Here\'s a screenshot of the twitter app for reference: http://screencast.com/t/YmFmYmI4M

What I want to do is place a floating pop-over on top of a substring in an NSAtt

4条回答
  •  离开以前
    2021-01-30 19:30

    The link given by George was very helpful and got me what I wanted. But strange thing happened. It was working in iOS SDK 4.0 but in the iOS SDK 5 the position of the link appeared in wrong position on the view.

    So I had to tweak the code a little bit. For the x coordinates of the touchable button, I had to use CTRunGetTypographicBounds instead of the CTRunGetImageBounds function.

    So over all, in the tweaked code: The y Coordinate , width and height was calculated using CTRunGetImageBounds. And x coordinate was calculated using CTRunGetTypographicBounds.

提交回复
热议问题