Search code examples
objective-cioscocoa-touchcore-text

Clickable area on Core Text CTFrame


I have some CTFrame columns of text placed on a UIScrollView and I made a selection tool to be able to select and highlight the text, as shown on image bellow.

I'd like to be able to click the selection, so the rectangles are UIButtons with 50% opacity, over the CTFrame.

The problem is the following: By some reason, the buttons TouchUpInside event isn't triggered and I think that if the highlight were placed bellow CTFrame, it would have a better effect, but I think the button wouldn't receive the event.

Any ideas to solve the problem, ie., to have a selection mark bellow text and clickable?


Here's the Text highlight example:

Text selection over CTFrame


Solution

  • How did you placed you CTFrames to UIScrollView ? CTFrame is not a UIView subclass. Where do you draw it? Also check your UIScroll view'a content size.

    Using UIButtons is not a good idea, It's better to draw it directly with Core Graphics. Touch should be handled bu UIView itself and then translated to appropriate text. Use CTFrameGetLineOrigins() to find the correct line (by checking the Y origins), and then using CTLineGetStringIndexForPosition() to find the correct character within the line (after subtracting the line origin from point).