Sublabel inside SwiftUI Menu Button

Viewed 522

I try to create a menu with buttons containing primary and secondary labels like the photo bellow using SwiftUI, so I embed the button and the text (as secondary label) in the VStack, but it's doesn't work. How I can create this view in swiftUI?

enter image description here

The Code

 Menu {
        Section {
            search
        }
        Section {
// The sort button
        Menu  {
            Picker("Sorting options", selection: $sort) {
                ForEach(SortType.allCases, id: \.self) { type in
                    Label("title", systemImage: "chevron.up")
                        .tag(type)
                }
            }
        } label: {
// Here I should embed title and subtitle like the photo but I don't know how.
            Label("Sort By", systemImage: "arrow.up.arrow.down")
        }
        }
    } label: {
        menuLabel
    }
1 Answers

You can achieve this by using UIKit since iOS 15.0

var menu = UIMenu()

if #available(iOS 15.0, *) {
   menu = UIMenu(title: "Sort By",
                 subtitle: "Name",
                 children: provideJobSortOptions())
} else {
   menu = UIMenu(title: "Sort By"), children: provideJobSortOptions())
}
Related