Closed xhzengAIB closed 10 years ago
Add this property in SETextView. @property (nonatomic) NSTextCheckingType dataDetectorTypes; In SETextLayout, change detectLinks function to this:
- (void)detectLinks:(NSTextCheckingType) checkingType
{
NSMutableArray *links = [[NSMutableArray alloc] init];
NSUInteger length = self.attributedString.length;
[self.attributedString enumerateAttribute:NSLinkAttributeName
inRange:NSMakeRange(0, length)
options:0
usingBlock:^(id value, NSRange range, BOOL *stop)
{
if (value) {
NSString *linkText = [self.attributedString.string substringWithRange:range];
SELinkText *link = [[SELinkText alloc] initWithText:linkText object:value range:range];
link.textType = NSTextCheckingTypeLink;
[links addObject:link];
}
}];
NSError* error = nil;
NSDataDetector* linkDetector = [NSDataDetector dataDetectorWithTypes:checkingType
error:&error];
NSRange range = NSMakeRange(0,length);
NSArray * dectectedLinks = [linkDetector matchesInString:self.attributedString.string options:0 range:range];
for (NSUInteger i = 0; i < [dectectedLinks count]; i++) {
NSTextCheckingResult* result = [dectectedLinks objectAtIndex:i];
NSString *linkText = [self.attributedString.string substringWithRange:result.range];
SELinkText *link = [[SELinkText alloc] initWithText:linkText object:nil range:result.range];
link.textType = result.resultType;
[links addObject:link];
}
_links = links.copy;
}
Job done!
Solution from https://github.com/mattt/TTTAttributedLabel
@hahaha12a2 Ok! Thanks you for your help.
Hi! @kishikawakatsumi Thank you for your great contribution.
Data detectors recognizes phone numbers, links, dates, etc????
Jack