【发布时间】:2014-09-07 20:24:48
【问题描述】:
我想让 TextView 中的匹配项是蓝色的。
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
标签: ios regex nsregularexpression