How to Change GraphicalDatePickerStyle
Date picker text color and Selection Colour:-
Code:-
DatePicker("Time",selection: dateProxy,displayedComponents: [.hourAndMinute])
.datePickerStyle(GraphicalDatePickerStyle())
.accentColor(.white)
.labelsHidden()
Output:-
But I want to achieve DatePicker
given below, is it possible in GraphicalDatePickerStyle
Style or not?
Try to Achieve:-
Seems like you are looking for the dark mode picker! Just apply the dark
colorScheme
to the component:
DatePicker("Time", selection: $date, displayedComponents: [.hourAndMinute])
.datePickerStyle(GraphicalDatePickerStyle())
.background(Color.black)
.environment(\.colorScheme, .dark) // <- This modifier
Also, you can apply the colorMultiply
modifier for coloring the picker in a pleasant way:
struct ContentView: View {
@State private var date = Date()
var colors: [Color] = [.white, .gray, .red, .green, .blue, .orange, .yellow, .pink, .purple] // <- You can use any color! This is just for demonstrate
var body: some View {
VStack {
ForEach(colors, id:\.self) { color in
DatePicker("Time", selection: $date, displayedComponents: [.hourAndMinute])
.datePickerStyle(GraphicalDatePickerStyle())
.background(Color.black.grayscale(1))
.colorMultiply(color) // <- This line does the trick
.environment(\.colorScheme, .dark) // <- Don't Forget this
}
}
}
}