更改NSButton的背景颜色 [英] Change background color of NSButton

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

问题描述

我在Mac应用程序中有一个NSButton,它的颜色我想改变程序,但没有我试图似乎工作。我试图在NSButtonCell上创建一个输出,并在那里设置背景颜色,但是没有工作。

I have an NSButton in a mac application whose colour I'd like to change programatically but nothing I tried seems to work. I tried to create an output on the NSButtonCell and set the background color there but that didn't work either. Any code snippets would be helpful.

推荐答案

标准的Aqua(药片状)按钮由系统绘制。他们没有背景颜色。事实上,他们是由可可拼接在一起的图像组成一个连贯的按钮图像。所以可可不能重新着色的图像到你的喜好。只有默认按钮(返回设置为其等效键值)将具有蓝色脉冲背景。

The standard Aqua (pill-shaped) buttons are drawn by the system. They don't have a background color as such. In fact, they are composed of images that Cocoa stitches together to make a coherent button image. So Cocoa can't recolor the images to your liking. Only the default button (the one with Return set as its key equivalent) will have a blue pulsing background.

它听起来像你想做的将涉及子类化 NSButtonCell 并做自己的绘图。如果您想重新着色按钮图片以获得所需的效果,则可以使用出色的主题公园实用程序来提取Apple的按钮图像的副本并使用它们。我承认自己这样做是为了窃取某些不能访问的界面元素,例如来自iTunes的滚动条。

What it sounds like you want to do will involve subclassing NSButtonCell and doing your own drawing. If you wanted to recolor the button images to get the effect you want, you can use the excellent Theme Park utility to extract copies of Apple's button images and use those. I'll admit to having done this myself in order to "steal" certain interface elements that aren't otherwise accessible, such as the scrollers from iTunes.

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

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