I have two MenuButtons, equivalent to NSPopupButtons in Cocoa. One has a list of years, starting at 2020, and the other lists calendar months. So I have the following test code to see how the MenuButton button works.
Initially being black, if I use the year menu button to select a year, its title color will turn light gray. If I touch the menu button with the mouse pointer, the title color will turn back black. If I click on the select me push button at the bottom to select a year, again, the title color will turn light gray. Is that how the menu button works? It's kind of a cheap Dutch doll. (No offense to Dutch people...). I think this stack overflow topic is what I'm talking about. Or am I doing something wrong? Thank you.
Code Block import SwiftUI struct ContentView: View { @State var yearSelection = 2020 @State var monthSelection = 12 @State var monthLiteral = "December" var body: some View { ZStack { VStack { Spacer() .frame(height: 8) HStack { Spacer() .frame(width: 16) MenuButton(String(yearSelection)) { ForEach((2020...2030), id: \.self) { year in Button(String(year)) { yearSelection = year } } }.frame(width: 68.0) MenuButton(monthLiteral) { ForEach((1...12), id: \.self) { month in let monStr = Calendar.current.monthSymbols[month - 1] Button(monStr) { monthSelection = month monthLiteral = monStr } } }.frame(width: 102.0) Spacer() } Spacer() Button("Select me") { yearSelection = 2024 } } }.frame(minWidth: 370, idealWidth: 370, maxWidth: 370, minHeight: 200, idealHeight: 200, maxHeight: 200, alignment: .center) } }
Initially being black, if I use the year menu button to select a year, its title color will turn light gray. If I touch the menu button with the mouse pointer, the title color will turn back black. If I click on the select me push button at the bottom to select a year, again, the title color will turn light gray. Is that how the menu button works? It's kind of a cheap Dutch doll. (No offense to Dutch people...). I think this stack overflow topic is what I'm talking about. Or am I doing something wrong? Thank you.