Objective c NSA指定的字符串可访问iOS

Objective c NSA指定的字符串可访问iOS,objective-c,core-text,nsattributedstring,Objective C,Core Text,Nsattributedstring,我知道如何在核心文本中设置一个可点击的url,但我不知道如何设置其他可点击的单词,如“我的名字是@george”。我希望@george在核心文本中可以被点击。有办法吗?我正试图这样做以使其可点击: CFAttributedStringSetAttribute(string, CFRangeMake( 0, mystring.length ), kCTFontAttributeName, ctFontBold ); CFAttributedStringSetAttribute(st

我知道如何在核心文本中设置一个可点击的url,但我不知道如何设置其他可点击的单词,如“我的名字是@george”。我希望@george在核心文本中可以被点击。有办法吗?我正试图这样做以使其可点击:

CFAttributedStringSetAttribute(string, CFRangeMake( 0, mystring.length ), kCTFontAttributeName, ctFontBold );
        CFAttributedStringSetAttribute(string, CFRangeMake( mystring.length, linestring.length ), kCTFontAttributeName, ctFont);
        CFAttributedStringSetAttribute(string, CFRangeMake( mystring.length, linestring.length ), kCTParagraphStyleAttributeName, paragraphStyle);
         CFAttributedStringSetAttribute(string, CFRangeMake(0, mystring.length), kCTForegroundColorAttributeName, [UIColor blackColor].CGColor);
             CFAttributedStringSetAttribute(string, CFRangeMake(0, mystring.length),
                                            (CFStringRef)@"CustomLink",mystring);
然后,当我点击这个单词时,我会像这样检索它:

NSString* myString = [attributes objectForKey:@"CustomLink"];
但我总是得到(空)。当它是URL时不会发生这种情况

感谢您的帮助

谢谢

我通过手势识别器检测触摸:

CTFrameRef ctFrame = CTFramesetterCreateFrame( framesetter, CFRangeMake(0, text.length),path, NULL );


    CFArrayRef lines = CTFrameGetLines(ctFrame);

    CGPoint* lineOrigins = malloc(sizeof(CGPoint)*CFArrayGetCount(lines));


    NSInteger index=0;

    int ii=0;

    for(CFIndex i = 0; i < CFArrayGetCount(lines); i++)
    {

        CGFloat y;

        CTFrameGetLineOrigins( ctFrame, CFRangeMake(0, 0), lineOrigins);


        CTLineRef line = (CTLineRef)CFArrayGetValueAtIndex(lines, i);
        CGPoint origin = lineOrigins[i];
        y = bottomLabel.bounds.origin.y +  bottomLabel.bounds.size.height - origin.y;
        ii=i;
        if (reversePoint.y > origin.y) {

            index = CTLineGetStringIndexForPosition(line, reversePoint);
            CFArrayRef runs = CTLineGetGlyphRuns(line);



            for(CFIndex j = 0; j < CFArrayGetCount(runs); j++)
            {
                CTRunRef run = CFArrayGetValueAtIndex(runs, j);

                CGRect runBounds;

                CGFloat ascent;//height above the baseline
                CGFloat descent;//height below the baseline
                runBounds.size.width = CTRunGetTypographicBounds(run, CFRangeMake(0, 0), &ascent, &descent, NULL);
                runBounds.size.height = ascent + descent;

                CGFloat xOffset = CTLineGetOffsetForStringIndex(line, CTRunGetStringRange(run).location, NULL);
                runBounds.origin.x = origin.x + rect.origin.x + xOffset;
                runBounds.origin.y = y;//+ rect.origin.y;
                runBounds.origin.y -= (descent+ascent)-5;


                NSDictionary* attributes = (NSDictionary*)CTRunGetAttributes(run);
                NSString* urlString = [attributes objectForKey:@"CustomLink"];
                               if(urlString && ![urlString isEqualToString:@""])
                {



                    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showwebview:) userInfo:urlString repeats:NO];



                    return;
                }
}
}
CTFrameRef-ctFrame=CTFramesetterCreateFrame(framesetter,CFRangeMake(0,text.length),path,NULL);
CFArrayRef lines=CTFrameGetLines(ctFrame);
CGPoint*lineOrigins=malloc(sizeof(CGPoint)*CFArrayGetCount(行));
NSInteger指数=0;
int ii=0;
对于(CFIndex i=0;i原点y){
索引=CtlineGetStringIndexFormosition(直线,反向点);
CFArrayRef runs=CTLineGetGlyphRuns(行);
对于(CFIndex j=0;j
使用。它支持超链接


请参阅如何使用示例。

使URL可点击的代码在哪里?请发布它!我已更新了使URL可点击的代码