我在NSTextView
中使用不同的字体,我想要做的是在tableView中显示某种字体的文本字符串。
如何枚举textView.attributedString()
并获取带有NSFont
名称作为参数的某些文字字符串?
答案 0 :(得分:0)
我目前无法尝试运行此代码,但我相信以下内容可以为您提供帮助:
NSMutableArray *matchingStrings = [NSMutableArray new];
[attributedText enumerateAttribute:NSFontAttributeName
inRange:NSMakeRange(0,attributedText.length)
options:0
usingBlock:(void (^ nonnull)(UIFont *font,
NSRange range,
BOOL * nonnull stop)){
if ([font.fontName isEqualToString: @"AvenirNext-Bold"])
{
NSAttributedString *attributedSubstring = [attributedText attributedSubstringFromRange:range];
[matchingStrings addObject:attributedSubstring.string];
}
}];