Вопрос

In Interface Builder you can set the style of a button to "Check" to turn it into a checkbox, and you can set the style of a button in code using NSButton's setButtonStyle: method, but how can I determine at runtime whether a particular NSButton is a checkbox (or radio button, or regular push button, etc)?

Part of the project I am working on requires loading views from other bundles and there is special behaviour required for each checkbox (these bundles are from 3rd parties).

Это было полезно?

Решение

I'm not sure there's a foolproof way to do this. You can check the bezelStyle, and for a checkbox that logs 2 (NSRegularSquareBezelStyle). I don't know if there are other buttons that have the NSRegularSquareBezelStyle, that are not check boxes. You'll probably have to experiment to find this out.

After Edit : I did find one other button that logs 2 for bezelStyle (the bevel button), but you can log [button.cell showsStateBy], and the check box was the only one I found that logs 1.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top