Recently introduced in WWDC 2020, Apple has given the Date & Time Picker an upgrade which looks more like AirBnB style. Since there isn’t any new way of calling this Date Picker, let’s just call it the Modern Date Picker.
Display a calendar date and provide controls for editing the date value.Apple Documentation
To follow along this tutorial, you’ll need some basic knowledge in:
- A basic familiarity with Swift.
- At least Xcode 12+
- Only supports iOS 14+
Modern Date Picker
To give you a better picture of the transformation, you will have a glimpse of how the traditional date picker looks like and hopefully you will come to appreciate the new design.
Next up, look at the Modern Date Picker with a one line of code.
datePicker.preferredDatePickerStyle = .compact
I was having difficulty wondering how do exit the pop up once I am done selecting the date and time. I am hoping to see a done button appear. Currently, by tapping any outside of the calendar will dismiss the calendar and thus reflecting your selection.
Navigating through the months and years is a very easy process as well.
Next, if you would like to have the calendar appear on the screen instead of a pop up, you may consider using
datePicker.preferredDatePickerStyle = .inline
Where to go From Here
Feel like UIKit is something that you will really like and want to explore more? Check out my page where you can learn how to use most of the components in UIKit.