Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI 2.0 Change DatePicker background

Tags:

swift

swiftui

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

like image 668
Darkisa Avatar asked Nov 06 '22 05:11

Darkisa


1 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
}
like image 178
Stan Avatar answered Dec 09 '22 06:12

Stan