I have used this StackOverflow Post to create a custom menu picker in SwiftUI:
struct MenuPicker: View {
@State var selection: String = "Option 1"
let menuOptions: [String] = ["Option 1", "Option 2", "Option 3"]
var body: some View {
Menu {
Picker(selection: $selection,
label: EmptyView(),
content: {
ForEach(menuOptions, id: .self) { option in
Text(option)
.tag(option)
}
}
)
.pickerStyle(.automatic)
} label: {
Text(selection)
.foregroundStyle(.white)
.padding(.vertical, 8)
.padding(.horizontal)
.background(.blue.opacity(0.7))
.cornerRadius(10)
}
}
}
When changing the selection, the dropdown looks as follows:
How to change the appearance of the dropdown? I would like to change background color (e.g. red), text color (e.g. green), and divider (e.g. white).