SwiftUI Datepicker changes format after selecting date

974 Views Asked by At

I've implemented a DatePicker with SwiftUI. It works for the most part as is should, but when selecting a specific date, e.g 26. Nov 2019, it changes the format of the displayed date text.


Exampels:

Expected: 26. Nov 2019

Got: 26.11.2019

Expected 27. Nov 2019

Got: 27. Nov 2019


I have tried using the environment with a specific locale but it did not fix it.

Building my own DatePicker works, but it's not what I want.

The DatePicker also print this in the console:

UIDatePicker is being laid out below its minimum width of 280. This may not look like expected, especially with larger than normal font sizes.

This is my SwiftUI code:

private struct GeneralSection: View {
    @ObservedObject var viewController: SettingsViewController
    
    var body: some View {
        Section(header: Text("General")) {
            TextField("Name", text: $viewController.coupleName)
            DatePicker(LocalizedStringKey("Date"),
                       selection: $viewController.coupleDate,
                       in: ...Date(),
                       displayedComponents: .date)
        }
    }
}

Gif from this problem

0

There are 0 best solutions below