nickcoding
nickcoding

Reputation: 475

SwiftUI 2 customizing GraphicalDatePickerStyle()

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)

shows what the date picker looks like

Anyone have any ideas with how to solve this?

Upvotes: 2

Views: 3435

Answers (1)

nicksarno
nicksarno

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

Related Questions