I'm trying to display a list of system voices, but I'd like to group them by region.
This is an example of select in html.
Ideally I'd like to create a dropdown that is similar to accessibility language selection.
Is there any way to replicate this in Interface Builder / swift? Any pointers would be appreciated.
Update:
The reason for this, is because I am displaying a list of speech voices to the user. At the moment, it mixes all the regions together, which is very confusing.
There is an update I'm working on, where I can display "English (United Kingdom)", but I'd like to group them up before releasing it.
I'm going to offer an answer in Objective-C because I'm not up on Swift. Sorry... You ought to be able to translate it easily enough, though, or I'm sure someone here can do it.
So, I managed this by making a subclass of NSMenu with the following method:
menuDividerString
in my case is @"----", andmenuSectionHeaderPrefix
is @".."; see the examples below.To make it work, do three things:
In IB, drill down the popup button until you see its menu, and set the class of the menu to 'MenuWithSections'. popup button drill-down
Turn off the popup button's 'autoenable' feature (click it off in the 'Attributes' tab of IB, or set it to NO programmatically)
In other words, to get the look you want in your question, pass the popup button titles like so:
sectioned popup
or if you want a divider-line between the two groups, use:
sectioned popup with divider
The following code groups menu, but not like the way you mentioned.
Add the popupbutton in your code and you will get results like this
Each one will be having its own items inside.
If you don't have the group heading, you can use the following code
Result :