f2cf74c7
yangbin
1.0.20(4)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
//
// DatePickerView.swift
// Twear
//
// Created by yangbin on 2021/12/24.
//
import UIKit
class DatePickerView: UIView {
typealias clickAlertClosure = (_ date: Date) -> Void
var clickClosure: clickAlertClosure!
private let bgView = UIView() //白色框
private lazy var titleLabel: UILabel = {
let label = UILabel()
|
884fc094
daifengyi
feat:date picker UI
|
19
20
|
label.font = RegularFont(20)
label.textColor = UIColor .rgbColorFromHex(0x333333)
|
f2cf74c7
yangbin
1.0.20(4)
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
label.textAlignment = .center
return label
}()
// private let minuteArray: [Int] = {
// var array: [Int] = []
// for i in 0..<50 {
// array.append((i+1)*1000)
// }
// return array
// }()
private lazy var sureBtn: UIButton = {
let button = UIButton()
button.addTarget(self, action: #selector(clickBtnAction(_:)), for: .touchUpInside)
|
884fc094
daifengyi
feat:date picker UI
|
35
36
37
|
button.layer.cornerRadius = 22
button.layer.masksToBounds = true
button.backgroundColor = UIColor .rgbColorFromHex(0x24C789)
|
f2cf74c7
yangbin
1.0.20(4)
|
38
|
button.setTitle(LocString("确定"), for: .normal)
|
884fc094
daifengyi
feat:date picker UI
|
39
|
button.titleLabel?.font = BoldFont(17)
|
f2cf74c7
yangbin
1.0.20(4)
|
40
41
42
43
44
45
46
|
button.tag = 1
return button
}()
private lazy var cancelBtn: UIButton = {
let button = UIButton()
button.addTarget(self, action: #selector(clickBtnAction(_:)), for: .touchUpInside)
|
884fc094
daifengyi
feat:date picker UI
|
47
|
button.setImage(UIImage(named: "close"), for: .normal)
|
f2cf74c7
yangbin
1.0.20(4)
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
button.tag = 2
return button
}()
lazy var datePicker: UIDatePicker = {
let picker = UIDatePicker()
picker.datePickerMode = .time
picker.locale = .current
if #available(iOS 13.4, *) {
picker.preferredDatePickerStyle = .wheels
} else {
}
return picker
}()
|
ebb6ae98
daifengyi
feat:data page na...
|
64
|
init(title: String, sureText: String = LocString("确定")) {
|
f2cf74c7
yangbin
1.0.20(4)
|
65
|
super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
|
ebb6ae98
daifengyi
feat:data page na...
|
66
|
createView(title: title, sureText: sureText)
|
f2cf74c7
yangbin
1.0.20(4)
|
67
68
69
|
}
|
ebb6ae98
daifengyi
feat:data page na...
|
70
|
func createView(title: String, sureText: String) {
|
f2cf74c7
yangbin
1.0.20(4)
|
71
72
73
74
75
76
77
|
self.backgroundColor = UIColor.black.withAlphaComponent(0.1)
bgView.backgroundColor = .white
// self.titleColor = titleColor
titleLabel.text = title
sureBtn.setTitle(sureText, for: .normal)
|
f2cf74c7
yangbin
1.0.20(4)
|
78
79
80
81
82
83
84
|
let lineView = UIView()
lineView.backgroundColor = LineColor
addSubview(bgView)
bgView.addSubview(titleLabel)
bgView.addSubview(sureBtn)
bgView.addSubview(cancelBtn)
|
f2cf74c7
yangbin
1.0.20(4)
|
85
86
87
88
|
bgView.addSubview(datePicker)
bgView.snp.makeConstraints { (make) in
make.left.right.bottom.equalToSuperview()
|
884fc094
daifengyi
feat:date picker UI
|
89
|
make.height.equalTo(340)
|
f2cf74c7
yangbin
1.0.20(4)
|
90
91
|
}
cancelBtn.snp.makeConstraints { make in
|
884fc094
daifengyi
feat:date picker UI
|
92
93
94
|
make.height.equalTo(78)
make.width.equalTo(58)
make.right.top.equalToSuperview()
|
f2cf74c7
yangbin
1.0.20(4)
|
95
|
}
|
884fc094
daifengyi
feat:date picker UI
|
96
|
|
f2cf74c7
yangbin
1.0.20(4)
|
97
|
sureBtn.snp.makeConstraints { make in
|
884fc094
daifengyi
feat:date picker UI
|
98
99
100
101
|
make.bottom.equalToSuperview().offset(-50)
make.left.equalToSuperview().offset(60)
make.right.equalToSuperview().offset(-60)
make.height.equalTo(44)
|
f2cf74c7
yangbin
1.0.20(4)
|
102
|
}
|
884fc094
daifengyi
feat:date picker UI
|
103
|
|
f2cf74c7
yangbin
1.0.20(4)
|
104
105
106
107
|
titleLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalTo(cancelBtn)
}
|
f2cf74c7
yangbin
1.0.20(4)
|
108
|
datePicker.snp.makeConstraints { make in
|
884fc094
daifengyi
feat:date picker UI
|
109
110
111
|
make.top.equalTo(cancelBtn.snp_bottom)
make.left.right.equalToSuperview()
make.bottom.equalTo(sureBtn.snp_top)
|
f2cf74c7
yangbin
1.0.20(4)
|
112
113
114
115
|
}
bgView.layoutIfNeeded()
|
884fc094
daifengyi
feat:date picker UI
|
116
|
bgView.setCorners(corners: [.topLeft, .topRight], radio: 12)
|
f2cf74c7
yangbin
1.0.20(4)
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
}
// @objc func dateChanged(datePicker : UIDatePicker){
// let formatter = DateFormatter()
// //日期样式
// formatter.dateFormat = "yyyy年MM月dd日 HH:mm:ss"
// print(formatter.string(from: datePicker.date))
// }
@objc func clickBtnAction(_ sender: UIButton) {
if clickClosure != nil && sender.tag == 1 {
clickClosure!(datePicker.date)
}
dismiss()
}
func show() {
let wind = KeyWindow
self.alpha = 0
wind.addSubview(self)
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.alpha = 1
})
}
@objc func dismiss() {
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.alpha = 0
}, completion: { (finish) -> Void in
if finish {
self.removeFromSuperview()
}
})
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}
|