SwiftUI DatePicker size not configurable

Hey guys,

I'm totally new to Swift programming and I'm setting up a view for registering users. I use a VStack to organize the TextFields as well as a DatePicker, but the last one seems to be very rebellious.

Here's my code:

        VStack {
            TextField("E-Mailadresse", text: $mail)
                .frame(height: 30)
                .textFieldStyle(.roundedBorder)
                .multilineTextAlignment(.center)
                .focused($hasFocus, equals: .mail)
                .onKeyPress(.tab, action: {hasFocus = .password; return .handled})
            SecureField("Passwort", text: $password)
                .frame(height: 30)
                .textFieldStyle(.roundedBorder)
                .multilineTextAlignment(.center)
                .focused($hasFocus, equals: .password)
                .onKeyPress(.tab, action: {hasFocus = .name; return .handled})
            TextField("Name", text: $name)
                .frame(height: 30)
                .textFieldStyle(.roundedBorder)
                .multilineTextAlignment(.center)
                .focused($hasFocus, equals: .name)
                .onKeyPress(.tab, action: {hasFocus = .prename; return .handled})
            TextField("Vorname", text: $prename)
                .frame(height: 30)
                .textFieldStyle(.roundedBorder)
                .multilineTextAlignment(.center)
                .focused($hasFocus, equals: .prename)
                .onKeyPress(.tab, action: {hasFocus = .birthday; return .handled})
            DatePicker("Geb.:", selection: $birthday, displayedComponents: [.date])
                .datePickerStyle(.wheel)
                .clipped()
                //.focused($hasFocus, equals: .birthday)
            Button("Registrieren") {self.register()}
                .padding(.top, 20)
                .keyboardShortcut(.defaultAction)
        }
        .frame(width: 375)
    }

And this is how it looks like:

As you can see, neither is the DatePicker centered correctly (it's more left located) nor is it clipped (reduced). I also tried adding a .frame() to itself, then I was ably to reduce it to the preferred height, but I can' reduce its width and as a result of this, I can also not write a full label like "Date of Birth" or something, because the wheel of the DatePicker always overlays it...

Is that a kind of misbehavior or am I missing something?

Thank you very much in anticipation for your feedback!

Kind regards

Kevin

Answered by darkpaw in 814851022

Try the other .datePickerStyle()s. You're using .wheel but something else might fit your UI better. I don't supply a style to mine, and I get this:

Try the other .datePickerStyle()s. You're using .wheel but something else might fit your UI better. I don't supply a style to mine, and I get this:

SwiftUI DatePicker size not configurable
 
 
Q