我正在做像facebook这样的标记功能,我已经可以标记用户了。我可以这样表现出来。这是由这段代码完成的。
NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:self.textView.text];
for (NSString *word in self.tagNameCollection) {
[string addColor:[UIColor redColor] substring:word];
[string addBackgroundColor:[Helpers getFromRGB:135 green:206 blue:250] substring:word];
}
所以,我有NSMutableAttributedString。我可以知道我在哪里更改了颜色,我的NSMutableAttributedString的字体?我可以知道该怎么办吗?
答案 0 :(得分:2)
您可以使用enumerateAttributesInRange:options:usingBlock:
获取NSAttributedString
的所有属性。
示例:
[attributedString enumerateAttributesInRange:NSMakeRange(0, [attributedString length])
options:0
usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
if ([attributes objectForKey:NSForegroundColorAttributeName])
NSLog(@"Found ForeGround Color: %@ in range %@", [attributes objectForKey:NSForegroundColorAttributeName], NSStringFromRange(range));
if ([attributes objectForKey:NSFontAttributeName])
NSLog(@"Found Font: %@ in range %@", [attributes objectForKey:NSFontAttributeName], NSStringFromRange(range));
if ([attributes objectForKey:NSBackgroundColorAttributeName])
NSLog(@"Found Background Color: %@ in range %@", [attributes objectForKey:NSBackgroundColorAttributeName], NSStringFromRange(range));
}];