How To Use Date Picker's in SwiftUI 2.0

Updated: Feb 19, 2021

Date Picker's are very useful in any app you are developing today!

Using Date Pickers just got so much easier to integrate in your app with SwiftUI 2.0!

Let's Explore How to use it! You Can Also Skip the Blog and watch the Youtube Video Directly!


Let's Start by creating a variable which will reference Date, so we can later use it!

@State var date = Date()

Inside your body add a VStack containing a Text followed b a DatePicker. Just like this.


VStack{
    Text("\(date)") //To display the Date by DatePicker
    DatePicker("Enter a Date", selection: $date)
}

With just those simple lines of code we have now integrated a simple Date Picker in our app. Run your app in the simulator and you will see it working perfectly. However, if you run the app you will realise that the date presented provides much more information than needed! To see how we can customise this, please continue by watching the video!

Thank You! Good Luck!

 

 

You Have Been working Hard! Treat YourSelf!


44 views1 comment