Reputation: 99
Is there any way to add title (Debug Menu) to the Menu
in iOS? I know it's possible in Swift/UIKit but I don't find a way in SwiftUI.
Upvotes: 9
Views: 4367
Reputation: 3324
Inspired by @narek.sv's answer, I tried giving the sections headers, and it turns out that works perfectly!
Menu("Example") {
Section("Header 1") {
Button("Item 1") {}
Button("Item 2") {}
}
Section("Header 2") {
Button("Item 1") {}
Button("Item 2") {}
}
}
Upvotes: 15
Reputation: 1575
There is no official solution for that, but you can achieve something similar using Section
s
Menu(content: {
Section {
Text("Title")
}
Section {
Button("Button 1") {
print("action 1")
}
Button("Button 2") {
print("action 2")
}
}
}, label: {
...
})
Upvotes: 11
Reputation: 281
Unfortunately, Apple does not provide this function. The title appears as a "button" that calls up the menu, but not again in the menu itself. Maybe this can be achieved with an own menustyle. You can find information about this here: https://developer.apple.com/documentation/swiftui/menu
Upvotes: 0