2013-12-11 41 views
0

我想使Facebook的标题UILabel。
我想要做的事情是在UILabel或UITextView中多次触摸。我应该使用什么?
我该如何制作这样的http://tool.keepitreal.jp/screen.png
在这种情况下,如果您触摸,每个名称将转到不同的页面。我怎么能把多个触摸像UILabel/UITextView的Facebook标题?

NSString* parts = @"this is test. you know?"; 

    NSError *error = nil; 
    NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"test" options:0 error:&error]; 
    if (error == nil) { 
     NSArray *res = [regexp matchesInString:parts.string options:0 range:NSMakeRange(0, parts.length)]; 
     for (NSTextCheckingResult *match in res) { 
      // change color 
      [parts addAttribute:NSForegroundColorAttributeName 
          value:[UIColor redColor] 
          range:[match rangeAtIndex:0]]; 
     } 
    } 
+0

使用[NSMutableAttributedString](https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSMutableAttributedString_Class/Reference/Reference.html)。 –

+0

我试过NSMutableAttributedString。我可以更改字体重量,但是我怎样才能在每个名字上设置事件。 – naohide

+0

@naofide:显示你试过的东西?你有使用'addAttribute'属性吗? –

回答

1

只需设置双击手势上的UITextView和事件处理方法:

CGPoint location = [gestureRecognizer locationInView:theTextView]; 
UITextPosition *tapPos = [self.textViewBelowPopup closestPositionToPoint:location]; 
UITextRange *wr = [self.textViewBelowPopup.tokenizer rangeEnclosingPosition:tapPos withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight]; 
NSString *word = [self.textViewBelowPopup textInRange:wr]; 

你有话进行比较,并显示其相应的屏幕/页。

+0

谢谢。我试过这个ñ我得到的话。但是,我有很多话。我想在更短的范围内得到这个词。我可以吗? – naohide

+0

对不起,我可以通过withGranularity:UITextGranularityWord来做到这一点。我使用了UITextGranularitySentence。非常感谢! – naohide

0

时尚秀,

它不可能在不同的位置上的一个控制分配两个敲击手势。您可以使用两个控件,一个是普通文本,另一个是属性文本,然后分配轻击手势。

有一个幸福的一天提前