更改 NSTextView 中的光标
我希望这将是一件相对容易的事情。
我正在编写一个 Mac 应用程序,它将(大部分)是一个巨大的 NSTextView。我想将默认文本位置光标覆盖为唯一的颜色/形状光标。我没有很多 Quartz 或一般绘图经验,但我可以自己研究更多。
我主要寻找的是关于实现这一点的最佳方法的建议。是否需要重写drawRect函数,调用super,然后实现我自己的绘制代码?
我如何找到适当的位置来绘制该光标?它是否包含在绘制矩形传递的矩形中?
I'm hoping this will be a relatively easy thing to do.
I am writing a Mac app that will be (mostly) a giant NSTextView. I would like to override the default text position cursor to a unique color/shape cursor. I don't have a lot of Quartz or general drawing experience but that's something I can look into more on my own.
What I'm primarily looking for is advice on the best way to implement this. Is it going to be a matter of overriding the drawRect function, calling the super, and then implementing my own draw code?
How would I find the appropriate location to draw that cursor? Is it contained within the drawRect's passed rect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本质上,您必须对 NSTextView 进行子类化并重写一些方法。显而易见的是
,但这似乎并不能完全解决这个问题。显然,您还必须重写私有方法:
在此处查找已经尝试执行此操作的人:
http://www.cocoadev.com/index.pl?CustomInsertionPoint
Essentially, you'll have to subclass the NSTextView and override some methods. The obvious one is
but that doesn't seem to entirely take care of it. Apparently, you also have to override a private method:
Look here for someone who's already trying to do this:
http://www.cocoadev.com/index.pl?CustomInsertionPoint