NSScrollView 中 NSTextView 周围的填充

发布于 2024-09-16 00:02:45 字数 438 浏览 2 评论 0原文

我想在 NSScrollView 内部的 NSTextView 周围提供一些像素的填充。我已经回顾过 这篇文章 并使用 setTextContainerInset 解决了这个问题左、右和下边距。但是一旦文本滚动,顶部缓冲区就会丢失。与重写 textContainerOrigin 相同。该帖子中的另一个答案指出:

TextEdit 执行此操作的方式(在换行到页面模式下)是将文本视图放入较大的视图中,并将该较大的视图设置为滚动视图的文档视图。

但如果我这样做(例如使用 NSBox),内容将不再滚动。我是否遗漏了有关该特定技巧的某些内容,或者人们可以建议其他任何技巧吗?

I'd like to provide a few pixels of padding around an NSTextView inside of an NSScrollView. I've reviewed this post and using setTextContainerInset does the trick for the left, right, and bottom margins. But as soon as the text scrolls the top buffer is lost. Same thing with overriding textContainerOrigin. Another answer in that post states:

The way TextEdit does it (when in Wrap to Page mode) is to put the text view inside of a larger view, and set that larger view as the document view of the scroll view.

But if I do that (using, say an NSBox) the content no longer scrolls. Am I missing something regarding that particular trick, or are there any other techniques that folks could suggest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城半夏 2024-09-23 00:02:45

您的报价中似乎缺少一个步骤。您需要确保新文档视图跟踪文本视图框架中的更改并调整自身大小以适应。您可以使用 -setPostsFrameChangedNotifications:,然后让您的新文档视图侦听来自文本视图的通知。

There's a step that seems to be missing from your quote. You'll need to make sure your new document view tracks the changes in the text view's frame and sizes itself to fit. You can turn on NSViewFrameDidChangeNotification on your text view with -setPostsFrameChangedNotifications:, then have your new document view listen for notifications from your text view..

差↓一点笑了 2024-09-23 00:02:45

顺便说一句,我最终通过子类化 NSClipView、重写 setFrame:、setFrameOrigin: 和 setFrameSize 并修改这些方法中的原点和宽度来添加填充来完成此任务。

By the way, I ended up accomplishing this by subclassing NSClipView, overriding setFrame:, setFrameOrigin:, and setFrameSize, and hacking the origin and width in those methods to add my padding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文