【发布时间】:2015-07-19 07:08:45
【问题描述】:
我在NSTextView中使用了不同的字体,我想做的是在tableView中显示一个特定字体的文本字符串。
如何枚举textView.attributedString() 并获取带有NSFont 名称作为参数的特定文本字符串?
【问题讨论】:
标签: objective-c macos swift nstextview
我在NSTextView中使用了不同的字体,我想做的是在tableView中显示一个特定字体的文本字符串。
如何枚举textView.attributedString() 并获取带有NSFont 名称作为参数的特定文本字符串?
【问题讨论】:
标签: objective-c macos swift nstextview
我目前无法尝试运行此代码,但我相信以下内容应该对您有所帮助:
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];
}
}];
【讨论】: