我想讓這些匹配在TextView中是藍色的。如何使突出顯示的匹配(NSRegularExpression)?
NSString *text = @"Except as contained in #wep this notice, the name of a copyright #ololo holder shall not be used in #pewpewpew advertising or otherwise to #promote";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"#\\w*" options:0 error:NULL];
NSArray *matches = [regex matchesInString:text options:0 range:NSMakeRange(0, [text length])];
NSLog(@"count %d", matches.count);
for (NSTextCheckingResult *match in matches) {
NSRange matchRange = [match range];
NSString *match = [text substringWithRange:matchRange];
NSLog(@"Matched string: %@", match);
}
self.myTextView.text = text;
使用'NSMutableAttributedString' – Hokage 2014-09-03 12:32:22