如何设置NSButton OSX的背景色 [英] how to set background color of NSButton OSX

查看:134
本文介绍了如何设置NSButton OSX的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置NSButton的背景色.属性检查器中没有任何内容,所以我想知道是否有任何方法可以通过编程方式做到这一点?

I want to set the background color of NSButton.There was nothing in the attribute inspector so i was wondering if there was any way to do it programmatically?

推荐答案

系统控件将需要遵循Apple的外观,因此您无法轻松更改背景颜色.如果要完成此操作,则需要子类NSButton并覆盖drawRect:方法.缺点是您还需要处理文本绘图,并可能根据按钮状态进行不同的渲染.

System controls will need to follow the Apple look&feel, so you cannot easily change the background colour. If you want to accomplish this, you'll need to subclass NSButton and overwrite the drawRect: method. The downside is that you'll also need to handle the text drawing, and possibly different rendering based on button state.

编辑.实际上,您需要将NSButtonCell类作为子类来绘制,更多信息可以在这里找到:

Edit. Actually, you'll need to subclass the NSButtonCell class for the drawing stuff, more info can be found here: https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSButtonCell_Class/index.html#//apple_ref/doc/uid/20000093-SW15

这篇关于如何设置NSButton OSX的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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