です。NSTextView [1]でHTMLのサブセットを編集中です。<時>タグをシミュレートしたいと思います。NSTextAttachmentCellの高さは
NSTextAttachmentとカスタムNSTextAttachmentCellを使用する方法がわかりました。添付ファイルとセルを挿入するためのコードがすべて記述されています。問題は、セルの下に膨大な空きスペースがあることです。
このスペースはセル自体の一部ではありません。セルの赤い領域全体をペイントすると正確に正しいサイズになりますが、テキストビューは次のテキスト行を赤の非常に下に置きます。額はどれくらい多くのテキストがの上にあるかによって異なります。セル。残念ながら、<時>タグが重要な長い文書で作業しています。これは、アプリケーションに大きな問題を引き起こします。
何が起こっているのですか?
私の細胞サブクラスのお金パーツ:
- (NSRect)cellFrameForTextContainer:(NSTextContainer *)textContainer
proposedLineFragment:(NSRect)lineFrag glyphPosition:(NSPoint)position
characterIndex:(NSUInteger)charIndex {
lineFrag.size.width = textContainer.containerSize.width;
lineFrag.size.height = topMargin + TsStyleBaseFontSize *
heightFontSizeMultiplier + bottomMargin;
return lineFrag;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
characterIndex:(NSUInteger)charIndex
layoutManager:(NSLayoutManager *)layoutManager {
NSRect frame = cellFrame;
frame.size.height -= bottomMargin;
frame.size.height -= topMargin;
frame.origin.y += topMargin;
frame.size.width *= widthPercentage;
frame.origin.x += (cellFrame.size.width - frame.size.width)/2;
[color set];
NSRectFill(frame);
}
[1]私はisEditableをセットし、それが生成マークアップのWebViewがunusablyダーティで特に、私は見つけることができませんでした試してみましたテキストをきちんと折り返す方法<p>タグ。あなたを変更してみてください
+ (NSAttributedString *)newHorizontalRuleAttributedStringWithStylebook:(TsStylebook*)stylebook {
TsHorizontalRuleCell * cell = [[TsHorizontalRuleCell alloc] initTextCell:@"—"];
cell.widthPercentage = 0.33;
cell.heightFontSizeMultiplier = 0.25;
cell.topMargin = 12.0;
cell.bottomMargin = 12.0;
cell.color = [NSColor blackColor];
NSTextAttachment * attachment = [[NSTextAttachment alloc] initWithFileWrapper:nil];
attachment.attachmentCell = cell;
cell.attachment = attachment;
NSAttributedString * attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@""];
[str appendAttributedString:attachmentString];
[str.mutableString appendString:@"\n"];
return str;
}
することができますあなたの 'NSTextView'にテキストの添付ファイルを挿入する方法を示すコードを投稿しますか? –
Rob、私が見たいコードを追加しました。これを見てくれてありがとう! –