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?
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
}
2
Answers
You can achieve this by using UIKit since iOS 15.0
I found a partial way to do this, but it is without the subtitle text smaller and in a
foregroundStyle(.secondary)
:Here, we are using Multi-Line Strings to trick it. I tried messing around with adding multiple
Text
s in a bunch ofStack
s. I even tried type erasing it withAnyView(erasing:)
, but somehow it’s still smarter. I even tried interpolatingText
views and addingText
modifiers like Bold, but it overrode that as well.Sorry for the spaces in between, but that is how I like to format my code.