在 NSButton 子类中绘制文本
如何在 NSButton 子类中添加按钮标题中的文本?
How would I add the text from the title of the button in my NSButton subclass?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在 NSButton 子类中添加按钮标题中的文本?
How would I add the text from the title of the button in my NSButton subclass?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
我认为它可能是这样工作的:
基于 iPhone 上的一些 Objective-C 知识并查看
http://www.cocoadev.com/index.pl?DrawingABoundedString
您可能对网站示例使用静态变量感到满意,也可能不满意。
正如你可能知道的那样,我不是。我的印象是当前图形上下文隐含在调用中。
您可能想根据按钮状态改变文本位置/颜色。
编辑编辑
代码以修复内存泄漏。
Here's how I think it might work:
based on a bit of Objective-C knowledge on an iPhone and looking at
http://www.cocoadev.com/index.pl?DrawingABoundedString
You may or may not be comfortable with the web site example's use of a static variable.
As you can probably gather I'm not. I get the impression the current graphics context is implicit in the call.
You probably want to vary the text position/color depending on button state.
EDIT
Code edited to fix memory leak.
您可以对
NSButtonCell
进行子类化,并重写可用于NSButtonCell
和NSCell
的各种draw
方法中的一个或多个。You subclass
NSButtonCell
, and override one or more of the variousdraw
methods available toNSButtonCell
andNSCell
.