你如何改变复选框的外观?

时间:2021-09-15 19:27:57

I would like to create a custom check box that functions just like a normal check box but looks different, at the moment I am using normal check box's, is there a way to do this.

我想创建一个自定义复选框,其功能就像一个普通的复选框,但看起来不同,目前我正在使用普通的复选框,有没有办法做到这一点。

P.S This is Cocoa i am talking about.

P.S这是我正在谈论的可可。

2 个解决方案

#1


You need to override NSButtonCell. You'll use drawInteriorWithFrame:inView: or a simililar method to do your custom drawing. If you've never used custom cells before it can be a bit of a learning experience, but there's a lot of good advice out there, like this page to start with.

您需要覆盖NSButtonCell。您将使用drawInteriorWithFrame:inView:或一个相似的方法来进行自定义绘图。如果你从来没有使用过自定义单元格,那么它可以是一种学习经验,但是那里有很多好的建议,就像这个页面一样。

You could also take a look at an open source framework like BGHUDAppKit for an example.

您还可以看一下像BGHUDAppKit这样的开源框架。

#2


As a sidenote, if the only thing you need to do is change the 'check' image from the default one provided by Apple, then go to the properties of the NSButton in XCode/Interface Builder and select an Image and an Alternate Image. Same thing goes for radio buttons.

作为旁注,如果您需要做的唯一事情就是从Apple提供的默认图像中更改“检查”图像,然后转到XCode / Interface Builder中的NSButton属性并选择图像和备用图像。单选按钮也是如此。

#1


You need to override NSButtonCell. You'll use drawInteriorWithFrame:inView: or a simililar method to do your custom drawing. If you've never used custom cells before it can be a bit of a learning experience, but there's a lot of good advice out there, like this page to start with.

您需要覆盖NSButtonCell。您将使用drawInteriorWithFrame:inView:或一个相似的方法来进行自定义绘图。如果你从来没有使用过自定义单元格,那么它可以是一种学习经验,但是那里有很多好的建议,就像这个页面一样。

You could also take a look at an open source framework like BGHUDAppKit for an example.

您还可以看一下像BGHUDAppKit这样的开源框架。

#2


As a sidenote, if the only thing you need to do is change the 'check' image from the default one provided by Apple, then go to the properties of the NSButton in XCode/Interface Builder and select an Image and an Alternate Image. Same thing goes for radio buttons.

作为旁注,如果您需要做的唯一事情就是从Apple提供的默认图像中更改“检查”图像,然后转到XCode / Interface Builder中的NSButton属性并选择图像和备用图像。单选按钮也是如此。