{
UIFont *boldFont = [UIFont boldSystemFontOfSize:10];
UILabel *sentenceLabel = [[UILabel alloc] init];
sentenceLabel.text = @"If you still feel the need to clean your ear, anything you can easily see or touch with the pad of your finger is fair game. But if you want to snake into your ear with a narrow tool, just remember this advice from Chandrasekhar: Nothing smaller than your elbow.";
NSString *sentence = sentenceLabel.text;
NSString *keyword = @"your";
[sentence enumerateSubstringsInRange:NSMakeRange(0, [sentence length])
options:NSStringEnumerationByWords
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
if ([substring isEqualToString:keyword]){
NSLog(@"%@", substring);
[attributedText addAttribute:NSFontAttributeName value:boldFont range:substringRange];
}
}];
[sentenceLabel setAttributedText:attributedText];
}
댓글 없음:
댓글 쓰기