0

I am trying to expand NSPopUpButton with Swift. For a native OSX app, I have to override a design like a screenshot below.

enter image description here

My purpose is adding a button as with down_iconand when I click it the popup button must expand. I can't do it in NSPopUpButton but in this question thread, this is possible for NSComboBox. Question Here

As I tried in NSComboBox,

comboBoxCell.performSelector(Selector("popUp:"))

code block not worked for NSPopUpButton because of there is no selector for NSPopUpButton for popping up.

Also, try

phoneCodesPopup.setAccessibilityExpanded(true)

but it is not expanded.

How can I open NSPopUpButton programmatically?

Thanks in advance!

eemrah
  • 1,603
  • 3
  • 19
  • 37
  • I just realised your question is contradictory: you said "I can't do [the design shown in the picture] in `NSPopUpButton`" so why are you still using an `NSPopupButton`? – Sweeper Jun 08 '20 at 16:32

1 Answers1

1

Unlike NSComboBox, clicking on NSPopoverButton, anywhere, will make it pop up, so you just need performClick:

yourPopup.performClick(nil)
Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • I will try it asap – eemrah Jun 08 '20 at 16:30
  • sorry for latency, it worked like charm. How can I understand it to get where can I use `performClick` or `setAccessibilityExpanded` ? Is there any reasonable perform documentation of it? I can not get it from the Apple documents when I read it. Thanks by the way – eemrah Jun 08 '20 at 17:51
  • 1
    @elia I haven't had much experience with `setAccessibilityExpanded`... I'm just not familiar with Accessibility in general, really. For `performClick`, it's basically an educated guess :) This is my thought process: I know that `NSPopoverButton` is a subclass `NSButton`, and I click on it to expand it, so naturally I reframed the problem as "how do I programmatically click an `NSButton`". Well, I know `performClick` does that. – Sweeper Jun 08 '20 at 18:04
  • so maybe lack of my experience on `Accessibility`. Can you recommend a blog post or tutorial for me to get better on this topic?. – eemrah Jun 08 '20 at 18:07
  • 1
    @elia maybe I haven’t made it clear, but I really don’t know much about accessibility, and do not have the experience to recommend a tutorial. But have you tried googling “macOS swift accessibility”? That’s what I would do if I wanted to learn more about it. – Sweeper Jun 08 '20 at 18:13
  • I was actually looking for a tutorial to better understand the topics we were talking about. Sorry for not being clear, thank you for the answer. – eemrah Jun 08 '20 at 18:22