文本在 NSTextFieldCell 的子类中消失

发布于 2024-09-30 04:18:39 字数 234 浏览 3 评论 0原文

我花了很多时间试图解决这个问题,但没有成功。不久前有人在苹果邮件列表上遇到了类似的问题,但没有人回答。基本上,它可以归结为:我对 NSTextFieldCell 进行了子类化并重写了 drawWithFrame: 方法来创建自定义边框。然后我在方法末尾调用drawInteriorWithFrame:来绘制文本。除了有时文本会消失之外,一切都很完美。除文本外,其他所有内容均已绘制。我认为这可能与字段编辑器有关,但我真的不知道。以前有人遇到过这个问题吗?

I've spent many hours trying to figure this one out with no luck. Someone had a similar problem on the Apple mailing lists a while ago and no one answered. Basically, it comes down to this: I've subclassed NSTextFieldCell and overridden the drawWithFrame: method to create a custom bezel. Then I call drawInteriorWithFrame: at the end of the method to draw the text. Everything works perfectly except for the fact that sometimes the text disappears. Everything else is drawn, except for the text. I think it might have something to do with the field editor, but I really don't know. Has anyone run into this problem before?

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

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

发布评论

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

评论(1

以往的大感动 2024-10-07 04:18:39

我很抱歉这个问题没有更好,但我觉得其他人有一天可能会遇到这个神秘的绘图问题,我已经找到了解决方案。子类化 NSTextFieldCell 的关键是,当您重写 drawWithFrame: 时,您需要调用 [super drawWithFrame:] ,否则您可能会遇到这些渲染问题。您可以将单元格的背景颜色设置为您想要的任何颜色,并使用 setClip 来获得所需的外观,但您不想自己完成所有绘图。至少这对我有用。

I apologize that this question wasn't better, but I feel others might run into this mysterious drawing problem someday and I have found a solution. The key to subclassing NSTextFieldCell is that when you override drawWithFrame:, you want to call [super drawWithFrame:] or else you might get these rendering problems. You can set the backgroundColor of the cell to whatever you want and use setClip to get the desired look, but you don't want to do all of the drawing yourself. At least this worked for me.

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