文本在 NSTextFieldCell 的子类中消失
我花了很多时间试图解决这个问题,但没有成功。不久前有人在苹果邮件列表上遇到了类似的问题,但没有人回答。基本上,它可以归结为:我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很抱歉这个问题没有更好,但我觉得其他人有一天可能会遇到这个神秘的绘图问题,我已经找到了解决方案。子类化 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.