2
我目前正在使用NSDataDetectors來查找鏈接:如何使用自定義NSDataDetector來檢測某些正則表達式模式?
-(void)setBodyText
{
NSString* labelText = [[message valueForKey:@"body"]gtm_stringByUnescapingFromHTML];
NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [linkDetector matchesInString:labelText options:0 range:NSMakeRange(0, [labelText length])];
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypeLink) {
NSURL *url = [match URL];
[bodyLabel addCustomLink:url inRange:[match range]];
NSLog(@"found URL: %@", url);
}
}
[bodyLabel setText:labelText];
[Utils alignLabelWithTop:bodyLabel];
}
如何使用NSDataDetectors解析@例如:
"Hello @sheehan, you are cool"
我希望它能夠檢測到@sheehan
注意:我想使用NSDataDetector或正則表達式模式匹配。沒有客戶標籤或控件等