Reputation: 475
So I have a datePicker that I am trying to implement in Dark Mode--it has a couple graphical glitches--namely, the selected date on the calendar has a white textColor, any way I can fix this? I highlighted the problem areas in red circles, essentially I just need to be able to change the toggle color and change today's date (when it's selected) to black textColor:
DatePicker("", selection: self.$Time, in: Date()..., displayedComponents: [.date, .hourAndMinute])
.datePickerStyle(GraphicalDatePickerStyle())
.colorMultiply(Color.black)
.colorInvert()
.foregroundColor(Color.white)
.background(Color.black)
Anyone have any ideas with how to solve this?
Upvotes: 2
Views: 3435
Reputation: 4235
There are limitations to customizing some SwiftUI elements. I tested this as well and it looks like in Dark Mode, there automatically is a white highlighted circle on the current date, which isn't customizable. I would propose the following, which uses a gray accent color when in Dark Mode:
@Environment(\.colorScheme) var colorScheme: ColorScheme
var body: some View {
DatePicker("", selection: $date, in: Date()..., displayedComponents: [.date, .hourAndMinute])
.datePickerStyle(GraphicalDatePickerStyle())
.accentColor(colorScheme == .dark ? Color.secondary : Color.primary)
.background(Color(UIColor.systemBackground))
}
Upvotes: 3