1

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

Daniel
  • 50
  • 1
  • 7
  • Curious, have you seen this same behavior if you had the `DatePicker` outside of the `Section` component? It seems like the spacing is changing as well. – cjpais Mar 26 '21 at 17:15
  • @cjpais yes, it does behave the same outside of the section. Looking at the view Debugger, the spacing does not change. The Label inside the `DatePickerLinkedLabel` is aligned on the left. Because its less text, it looks like the spacing is changing. – Daniel Mar 27 '21 at 18:35
  • Quite odd. I am also easily able to replicate this, both on the simulator and on device. Might be worth filing a bug with Apple. This seems to be unexpected behavior – cjpais Mar 30 '21 at 15:48

0 Answers0