IOS TOPICS

IOS Introduction
Swift UI Label
Swift UI Button
Swift UI Text Field
Swift UI Slider
Swift UI Switch
Swift UI Stepper
Swift UI Date Picker
Swift UI Segmented Control
Views
Table View
Collection Views
SCROLL VIEW
iOS Content View
iOS View Controllers
iOS Bar interface
iOS Navigation interface
iOS Architect Pattern
iOS Libraries
iOS Web request and parsing
iOS user defaults
iOS Coredata and database

Creating Date picker


Creating the Simplest Form of a Date picker:

Launch a new project in Xcode from the Launchpad on your Mac. You should see the welcome screen as shown below.

ios output

(If you don’t then go to file>new>playground)

ios output

Click on “Create a new Xcode project

ios output

The dialog that pops up allows you to choose a template for your project. For the purposes of this article choose “App” under “Application.”

ios output

The following dialog box opens up. Here you can name the project TestStepper, choose the type of interface as “SwiftUI” and select the Life Cycle as “SwiftUI App” & finally the language you want to continue in as “Swift”.

ios output

Finally, choose where you’d like to save the file and click create.

ios output

In the canvas, next to the code editor, click Resume to display the preview. If it isn’t visible, go to Editor and click Editor and Canvas to view it.

From the left hand side of the window, select ContentView.swift and you can create a simple date picker using the following piece of code

Creating the most basic form of a Date Picker

Code:

struct ContentView: View { @State var birthday = Date() var body: some View { VStack { DatePicker("", selection: $birthday, displayedComponents: .date) Text("Your birthday is on: \(birthday)") }.padding() } }

Output:

This is the first screen we see

ios output

Creating the most basic form of a Date Picker

Code:

struct ContentView: View { @State var birthday = Date() var body: some View { VStack { DatePicker("", selection: $birthday, displayedComponents: .date) Text("Your birthday is on: \(birthday)") }.padding() } }

Output:

On clicking on the date, a calendar pops up, and we can change the date and its reflected in the output text below.

ios output