-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTimeSelector.swift
50 lines (32 loc) · 1.75 KB
/
DateTimeSelector.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
40
41
42
43
44
45
46
47
48
49
50
import Foundation
import UIKit
import SwiftUI
import DateTimePicker
struct DateTimeSelector: UIViewRepresentable {
@EnvironmentObject var viewRouter: ViewRouter
@State var completion: () -> Void
@Binding var show: Bool
@Binding var dateOutput: Date
func makeUIView(context: Context) -> DateTimePicker {
let v = DateTimePicker.create(minimumDate: Date().addingTimeInterval(-60*60*24*1), maximumDate: Date().addingTimeInterval(60*60*24*14))
v.timeInterval = DateTimePicker.MinuteInterval.fifteen
v.includesSecond = false
v.is12HourFormat = true
v.customFontSetting = DateTimePicker.CustomFontSetting(cancelButtonFont: UIFont(name: "OpenSans-Semibold", size: 15)!, todayButtonFont: UIFont(name: "OpenSans-Semibold", size: 15)!, doneButtonFont: UIFont(name: "OpenSans-Semibold", size: 15)!, selectedDateLabelFont: UIFont(name: "OpenSans-Regular", size: 12)!, timeLabelFont: UIFont(name: "OpenSans-Semibold", size: 17)!, colonLabelFont: UIFont(name: "OpenSans-Semibold", size: 17)!, dateCellNumberLabelFont: UIFont(name: "OpenSans-Semibold", size: 25)!, dateCellDayMonthLabelFont: UIFont(name: "OpenSans-Regular", size: 10)!)
v.highlightColor = #colorLiteral(red: 0.3490196078, green: 0.3137254902, blue: 0.6509803922, alpha: 1)
v.completionHandler = { date in
dateOutput = date
show = false
completion()
}
v.dismissHandler = {
show = false
}
return v
}
func updateUIView(_ dateTimeSelector: DateTimePicker, context: Context) {
if show{
dateTimeSelector.show()
}
}
}