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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//
// MOFSPickerManager.m
// MOFSPickerManager
//
// Created by lzqhoh@163.com on 16/8/26.
// Copyright © 2016年 luoyuan. All rights reserved.
//
#import "MOFSPickerManager.h"
@implementation MOFSPickerManager
+ (MOFSPickerManager *)shareManger {
static MOFSPickerManager *manager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager = [self new];
});
return manager;
}
- (MOFSDatePicker *)datePicker {
if (!_datePicker) {
_datePicker = [MOFSDatePicker new];
}
return _datePicker;
}
- (MOFSPickerView *)pickView {
if (!_pickView) {
_pickView = [MOFSPickerView new];
}
return _pickView;
}
- (MOFSAddressPickerView *)addressPicker {
if (!_addressPicker) {
_addressPicker = [MOFSAddressPickerView new];
}
return _addressPicker;
}
// ================================DatePicker===================================//
- (void)showDatePickerWithTag:(NSInteger)tag commitBlock:(DatePickerCommitBlock)commitBlock cancelBlock:(DatePickerCancelBlock)cancelBlock {
self.datePicker.datePickerMode = UIDatePickerModeDate;
self.datePicker.toolBar.titleBarTitle = @"";
self.datePicker.toolBar.cancelBarTitle = @"取消";
self.datePicker.toolBar.commitBarTitle = @"确定";
self.datePicker.minimumDate = nil;
self.datePicker.maximumDate = nil;
[self.datePicker showMOFSDatePickerViewWithTag:tag firstDate:nil commit:^(NSDate *date) {
if (commitBlock) {
commitBlock(date);
}
} cancel:^{
if (cancelBlock) {
cancelBlock();
}
}];
}
- (void)showDatePickerWithTag:(NSInteger)tag datePickerMode:(UIDatePickerMode)mode commitBlock:(DatePickerCommitBlock)commitBlock cancelBlock:(DatePickerCancelBlock)cancelBlock {
self.datePicker.datePickerMode = mode;
self.datePicker.toolBar.titleBarTitle = @"";
self.datePicker.toolBar.cancelBarTitle = @"取消";
self.datePicker.toolBar.commitBarTitle = @"确定";
self.datePicker.minimumDate = nil;
self.datePicker.maximumDate = nil;
[self.datePicker showMOFSDatePickerViewWithTag:tag firstDate:nil commit:^(NSDate *date) {
if (commitBlock) {
commitBlock(date);
}
} cancel:^{
if (cancelBlock) {
cancelBlock();
}
}];
}
- (void)showDatePickerWithTag:(NSInteger)tag title:(NSString *)title cancelTitle:(NSString *)cancelTitle commitTitle:(NSString *)commitTitle datePickerMode:(UIDatePickerMode)mode commitBlock:(DatePickerCommitBlock)commitBlock cancelBlock:(DatePickerCancelBlock)cancelBlock {
self.datePicker.datePickerMode = mode;
self.datePicker.toolBar.titleBarTitle = title;
self.datePicker.toolBar.cancelBarTitle = cancelTitle;
self.datePicker.toolBar.commitBarTitle = commitTitle;
self.datePicker.minimumDate = nil;
self.datePicker.maximumDate = nil;
[self.datePicker showMOFSDatePickerViewWithTag:tag firstDate:nil commit:^(NSDate *date) {
if (commitBlock) {
commitBlock(date);
}
} cancel:^{
if (cancelBlock) {
cancelBlock();
}
}];
}
- (void)showDatePickerWithTag:(NSInteger)tag firstDate:(NSDate *)firstDate minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate datePickerMode:(UIDatePickerMode)mode commitBlock:(DatePickerCommitBlock)commitBlock cancelBlock:(DatePickerCancelBlock)cancelBlock {
self.datePicker.datePickerMode = mode;
self.datePicker.toolBar.titleBarTitle = @"";
self.datePicker.toolBar.cancelBarTitle = @"取消";
self.datePicker.toolBar.commitBarTitle = @"确定";
self.datePicker.minimumDate = minDate;
self.datePicker.maximumDate = maxDate;
[self.datePicker showMOFSDatePickerViewWithTag:tag firstDate:firstDate commit:^(NSDate *date) {
if (commitBlock) {
commitBlock(date);
}
} cancel:^{
if (cancelBlock) {
cancelBlock();
}
}];
}
- (void)showDatePickerWithTitle:(NSString *)title cancelTitle:(NSString *)cancelTitle commitTitle:(NSString *)commitTitle firstDate:(NSDate *)firstDate minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate datePickerMode:(UIDatePickerMode)mode tag:(NSInteger)tag commitBlock:(DatePickerCommitBlock)commitBlock cancelBlock:(DatePickerCancelBlock)cancelBlock {
self.datePicker.datePickerMode = mode;
self.datePicker.toolBar.titleBarTitle = title;
self.datePicker.toolBar.cancelBarTitle = cancelTitle;
self.datePicker.toolBar.commitBarTitle = commitTitle;
self.datePicker.minimumDate = minDate;
self.datePicker.maximumDate = maxDate;
[self.datePicker showMOFSDatePickerViewWithTag:tag firstDate:firstDate commit:^(NSDate *date) {
if (commitBlock) {
commitBlock(date);
}
} cancel:^{
if (cancelBlock) {
cancelBlock();
}
}];
}
// ================================pickerView===================================//
- (void)showPickerViewWithDataArray:(NSArray *)array tag:(NSInteger)tag title:(NSString *)title cancelTitle:(NSString *)cancelTitle commitTitle:(NSString *)commitTitle commitBlock:(PickerViewCommitBlock)commitBlock cancelBlock:(PickerViewCancelBlock)cancelBlock {
self.pickView.showTag = tag;
self.pickView.toolBar.titleBarTitle = title;
self.pickView.toolBar.cancelBarTitle = cancelTitle;
self.pickView.toolBar.commitBarTitle = commitTitle;
[self.pickView showMOFSPickerViewWithDataArray:array commitBlock:^(NSString *string) {
if (commitBlock) {
commitBlock(string);
}
} cancelBlock:^{
if (cancelBlock) {
cancelBlock();
}
}];
}
//===============================addressPicker===================================//
- (void)showMOFSAddressPickerWithTitle:(NSString *)title cancelTitle:(NSString *)cancelTitle commitTitle:(NSString *)commitTitle commitBlock:(void(^)(NSString *address, NSString *zipcode))commitBlock cancelBlock:(void(^)())cancelBlock {
self.addressPicker.toolBar.titleBarTitle = title;
self.addressPicker.toolBar.titleBarTextColor = [UIColor blackColor];
self.addressPicker.toolBar.cancelBarTitle = cancelTitle;
self.addressPicker.toolBar.commitBarTitle = commitTitle;
[self.addressPicker showMOFSAddressPickerCommitBlock:^(NSString *address, NSString *zipcode) {
if (commitBlock) {
commitBlock(address, zipcode);
}
} cancelBlock:^{
if (cancelBlock) {
cancelBlock();
}
}];
}
- (void)searchAddressByZipcode:(NSString *)zipcode block:(void(^)(NSString *address))block {
[self.addressPicker searchType:SearchTypeAddress key:zipcode block:^(NSString *result) {
if (block) {
block(result);
}
}];
}
- (void)searchZipCodeByAddress:(NSString *)address block:(void(^)(NSString *zipcode))block {
[self.addressPicker searchType:SearchTypeZipcode key:address block:^(NSString *result) {
if (block) {
block(result);
}
}];
}
@end