SwiftUI 2.0 Change DatePicker background

Viewed 2588

Is there anyway to change the background color of the DatePicker view? I have the following Picker:

DatePicker(selection: $form.start, in: Date()..., displayedComponents: .date) {}
            .padding(.vertical, 6)
            .labelsHidden()
            .accentColor(.black)

But the picker has that grayish tint around the date (See image below). I just want the entire background to be white. I tried .background(Color.white) but that doesn't do anything. How can I make the entire background white?

enter image description here

2 Answers

I discovered that you can do this by initialising it as follows:

init() {
 UIDatePicker.appearance().backgroundColor = UIColor.init(.white) // changes bg color
        UIDatePicker.appearance().tintColor = UIColor.init(.white) // changes font color
}

You can do this as follows:

dateTimePicker.setValue(UIColor.white, forKey: "backgroundColor")

enter image description here

Related