Rob*_*ger 10
这实际上有点复杂.您需要NSTextAttachment
为每个"令牌" 创建一个自定义,并将其插入到NSTextStorage
您的NSTextView
.
Dejal Systems的David Sinclair发表了一篇很棒的文章,解释了如何做到这一点.
小智 5
我找到了一种简单的方法,使用自定义单元类作为标记:
NSTextAttachmentCell
编写一个继承并重新实现的单元类- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
NSTextView
.NSTextAttachment
将标记插入文本视图的方法可能如下所示:
- (void)insertAttachmentCell:(NSTextAttachmentCell *)cell toTextView:(NSTextView *)textView
{
NSTextAttachment *attachment = [NSTextAttachment new];
[attachment setAttachmentCell:cell];
[textView insertText:[NSAttributedString attributedStringWithAttachment:attachment]];
}
Run Code Online (Sandbox Code Playgroud)
这种方法比David Sinclair的方法更适合代币。不需要使用文件包装器,因为我们想要显示动态内容(令牌)而不是静态图像。
不过,了解一下大卫的概念可能会有用。他描述了一种实现拖放的好方法。复制粘贴功能。
归档时间: |
|
查看次数: |
2469 次 |
最近记录: |