13

属性付きの文字列を NSTextView に貼り付けようとしていますが、プレーン テキストとして表示され、属性は表示されません。私は次のように文字列を作成しました:

    NSString *str = @"Parsing Directory Structure\n\n";

NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc] initWithString:str];
NSDictionary *attributes = @{
                             NSForegroundColorAttributeName : [NSColor blueColor],
                             NSFontAttributeName : [NSFont fontWithName:@"HelveticaNeue-Bold" size:20.f]
                             };
[attrstr setAttributes:attributes range:NSRangeFromString(str)];

[[self.textView textStorage] appendAttributedString:attrstr];

NSTextView (スクロール ビュー内) では、[リッチ テキストを許可する] チェック ボックスはオンのままで、[編集可能] チェック ボックスはオフになっています。私は基本的にこれをコンソール出力ウィンドウのように使用しようとしています。

4

1 に答える 1