【问题标题】:How to get a string of certain font text in a NSTextView?如何在 NSTextView 中获取特定字体文本的字符串?
【发布时间】:2015-07-19 07:08:45
【问题描述】:

我在NSTextView中使用了不同的字体,我想做的是在tableView中显示一个特定字体的文本字符串。

如何枚举textView.attributedString() 并获取带有NSFont 名称作为参数的特定文本字符串?

【问题讨论】:

    标签: objective-c macos swift nstextview


    【解决方案1】:

    我目前无法尝试运行此代码,但我相信以下内容应该对您有所帮助:

    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];
        }
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-30
      • 2017-01-09
      • 1970-01-01
      • 1970-01-01
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      相关资源
      最近更新 更多