2014년 5월 2일 금요일

string에서 keyword를 찾아 빨간색으로 표시하기




// search matching keyword
    NSRegularExpression *regex = [NSRegularExpression
                                  regularExpressionWithPattern:searchKeyword
                                  options:NSRegularExpressionCaseInsensitive
                                  error:nil];
    [regex enumerateMatchesInString:fullString options:0 range:NSMakeRange(0, [fullString length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop){
        [attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:result.range];
        
        [self.label setAttributedText:attributedText];

    }];

댓글 없음:

댓글 쓰기