1

I used CoreText to layout a custom view. Want to know on which word I tapped on event/gesture with CoreText.

I did following code within my drawRect:

CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSelectFont(context, "Helvetica-Bold", FONTSIZE, kCGEncodingMacRoman);

//setSpan
CGContextSetTextPosition(context, 0, (200+offset) - (i*25));
CGContextShowText(context,[[dispLineArray objectAtIndex:i] UTF8String], strlen([[dispLineArray objectAtIndex:i] UTF8String]));
Fogmeister
  • 76,236
  • 42
  • 207
  • 306

2 Answers2

0

in this answered question you can find information about CoreText and touch gestures:

Using CoreText and touches to create a clickable action (not tested by me!)

In the example you can see how to get the string character index from the touch position. After this, you can extract the word using differents methods like split the NSString in two NSString by character position, then split boths by white space character. Now, we have two NSArray. After this take last and first element of boths NSArray and merge into one NSString. And you have the word.

It's a rudimentary and surely there are better ways to do this using regular expressions or other techniques.

Community
  • 1
  • 1
Carlos Jiménez
  • 527
  • 5
  • 15
0

If display view is a uiview .You can use view's gestureRecognizer do it . If display view is a custom GTFrameRef use uiresponse touch founcations .

user3339784
  • 41
  • 1
  • 7