4
votes

Is there a way to hide the pop-up button of an NSComboBox? I can't find anything in the documentation for NSComboBox or NSComboBoxCell. There is a setButtonBordered: method on NSComboBox, but this just changes to an alterate button style.

If I can't hide it, can I at least disable it?

2
I posted a workaround below which may work for you. In my application I'd still like to be able to hide it, so I'd be happy to hear other answers.paulmelnikow

2 Answers

0
votes

If the combo box has no items, clicking the pop-up button doesn't do anything.

Maybe you can work around the limitation by emptying the list when you want to disable the button.

It makes clicking have no effect, but it doesn't hide the button or draw it as disabled.

0
votes

I don't think this is possible. An NSComboBox without the button is effectively an NSTextField, so I guess it was deemed unnecessary. You could probably do this by subclassing NSComboBoxCell and override -drawWithFrame:inView: or -drawInteriorWithFrame:inView:.

Safest way would probably be to add your own buttonHidden property and use the ObjC runtime method class_getMethodImplementation to look up the IMP for the same method in NSTextField and just call that when the button is hidden. You'd effectively be calling super's super, so you'd get a regular text field look.