2
편집 할 수없는 텍스트를 표시하기 위해 NSTextView를 사용하고 있으며 문자열 내에있는 링크를 강조 표시하려고합니다. 링크를 파싱하고 속성을 추가하는 코드를 보았습니다. 그건 잘 작동하지만, 어떻게 든 내장 링크 검색을 어떻게 든 재사용 할 수 있는지 궁금 해서요.편집 할 수없는 NSTextView가 setAutomaticLinkDetectionEnabled를 사용하여 링크를 강조 표시 할 수 있습니까?
내가 해봤 설정 :
[textView setEnabledTextCheckingTypes:NSTextCheckingTypeLink];
[textView setAutomaticLinkDetectionEnabled:YES];
및 사용 :
[textView checkTextInDocument:nil];
문자열을 설정 한 후.
- (void)highlightLinksInTextView:(NSTextView *)view {
NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [linkDetector matchesInString:view.string options:0 range:NSMakeRange(0, view.string.length)];
[view.textStorage beginEditing];
for (NSTextCheckingResult *match in matches) {
if (!match.URL) continue;
NSDictionary *linkAttributes = @{
NSLinkAttributeName: match.URL,
};
[view.textStorage addAttributes:linkAttributes range:match.range];
}
[view.textStorage endEditing];
}
불행하게도 당신이 당신이를 NSTextView 문자열을 설정 때마다 전화를해야 : 완성도를 위해서