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

selection of time


selection of time:

To allow selection of time, we need to the arguments in “displayedComponents” to include a .hourandMinute as shown below:

Code:

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

Output:

As can be seen below, we now have another section to input the time as well.

ios output

This is what it looks like on clicking on either of the two input boxes.:

ios output

Tip: Similarly, by using just .hourandMinute, one can simply accept time as the input without the date. This is what that would look like-

ios output