-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatePickers.swift
39 lines (33 loc) · 998 Bytes
/
DatePickers.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import SwiftUI
struct DatePickers: View {
@State var birthDate: Date = Date()
let startingDate: Date = Calendar.current.date(from: DateComponents(year: 2022)) ?? Date()
let endingDate: Date = Date()
var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .medium
return formatter
}
var body: some View {
VStack {
Text("Selected date is:")
Text("\(dateFormatter.string(from: birthDate))")
DatePicker(
"Birth Date",
selection: $birthDate,
in: startingDate...endingDate,
displayedComponents: [.date, .hourAndMinute]
)
.datePickerStyle(
// .graphical
// .wheel
.compact
)
.tint(.green)
}
}
}
#Preview {
DatePickers()
}