Does anybody know how to change the size of the default DatePicker in SwiftUI? I have been trying to provide a custom frame to resize the DatePicker but I could't see the expected outcome.
Thanks in advance!
Here is what I tried
DatePicker("", selection: $currentDate, displayedComponents: .hourAndMinute)
.labelsHidden()
.frame(width: 150, height: 80, alignment: .center)
SwiftUI: DatePicker & TimePicker Published by Kelvin Tan on December 18, 2019 DatePicker gives you the flexibility of either selecting only the date or both the date and time. It’s a useful tool if you would like to give the user’s input on either date or time.
We can change our example to display time view for DatePicker by simply replacing .date with .hourAndMinute We can limit the DatePicker to specific ranges of dates, allowing date selections only before or, after a certain date, or between two dates.
DatePicker gives you the flexibility of either selecting only the date or both the date and time. It’s a useful tool if you would like to give the user’s input on either date or time.
.automatic : sets DatePicker style based on system its being rendered. .compact : sets DatePicker style to compact display which renders date and time views that can be tapped to reveal calendar and time picker. .graphical : sets DatePicker style to display calendar view.
Just clip it at the end as below...
DatePicker("", selection: $currentDate, displayedComponents: .hourAndMinute)
.labelsHidden()
.frame(width: 150, height: 80, alignment: .center)
.clipped()
I added .scaleEffect() after the datepicker, and now I can achieve size scaling...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With