如何创建一个自定义主题的NSButton? [英] How do you create a custom themed NSButton?

查看:139
本文介绍了如何创建一个自定义主题的NSButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建自定义主题的NSButton?我不是一个小方式,如改变背景颜色或从圆角边缘变为方形边缘。我想替换整个按钮的外观和感觉。这是可能在可可粉做吗?显然,我必须子类NSButton类,并从那里去。任何帮助将不胜感激。

How do you create a custom themed NSButton? I don't mean in a small way like changing the background color or changing from rounded edges to square edges. I want to replace the entire look and feel of the button. Is that even possible to do in Cocoa? Obviously I would have to subclass the NSButton class and go from there. Any help would be much appreciated.

推荐答案

实际上,你需要子类 NSButtonCell 。您应该阅读 Apple的文档,以更好地了解它们如何交互。您可能仍然希望子类 NSButton ,以便它也将使用您的 NSButtonCell 子类。

Actually, you need to subclass NSButtonCell. You should read Apple's documentation on this to gain a better understanding of how they interact. You probably will still want to subclass NSButton so that it will use your NSButtonCell subclass, too.

对于一个按钮,大部分工作是在 drawBezelWithFrame:inView:中完成的。如果你想改变文本或图像的绘制方式,你会覆盖 drawText:withFrame:inView: drawImage:withFrame:inView: / code>。

For a button, most of the work is done in drawBezelWithFrame:inView:. If you want to alter the way the text or image is drawn, you would override drawText:withFrame:inView: and drawImage:withFrame:inView:.

这篇关于如何创建一个自定义主题的NSButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆