我想在菜单中使用选择器时显示选择,就像在提醒应用程序中的排序方式一样,我无法为我的生活弄清楚如何做到这一点。
这就是我想要的:
https://i.stack.imgur.com/Lwm2R.jpg
下面是我的代码:
private func menuButton() -> some View {
Menu {
Menu {
Picker(selection: $group, label: Text("Grouping options")) {
Text("None").tag(0)
Text("Type").tag(1)
}
} label: {
Label("Group By", systemImage: "square.grid.3x1.below.line.grid.1x2")
}
Menu {
Picker(selection: $sort, label: Text("Sorting options")) {
Text("Name").tag(0)
Text("Priority").tag(1)
}
} label: {
Label("Sort By", systemImage: "arrow.up.arrow.down")
}
Divider()
Button {
toggleInbox()
} label: {
Label(inboxList?.isHidden == false ? "Hide Inbox" : "Show Inbox", systemImage: inboxList?.isHidden == false ? "eye.slash" : "eye")
}
} label: {
Image(systemName: "ellipsis.circle.fill")
.font(.custom("Button", size: 22))
.foregroundStyle(.blue, Color(UIColor.systemGray5))
}
}
字符串
1条答案
按热度按时间mum43rcc1#
使用
Button
作为Menu
的标签(参见Swiftui: multiple lines in a menu item or picker):字符串
另一个提示:您可以在
Picker
上使用.pickerStyle(.menu)
,因此不必将其 Package 在Menu
中。